Beautiful Soup

维基百科,自由的百科全书
跳转到导航 跳转到搜索
Beautiful Soup
原作者Leonard Richardson
当前版本
    Module:EditAtWikidata第29行Lua错误:attempt to index field 'wikibase' (a nil value)
    源代码库
    • {{URL|example.com|可选的显示文本}}
    Module:EditAtWikidata第29行Lua错误:attempt to index field 'wikibase' (a nil value)
    编程语言Python
    引擎
      Module:EditAtWikidata第29行Lua错误:attempt to index field 'wikibase' (a nil value)
      类型HTML解析库、网络数据采集
      许可协议Python软件基金会许可证 (Beautiful Soup 3及以前)
      MIT许可证(Beautiful 4及以后)[1]
      网站www.crummy.com/software/BeautifulSoup/

      Beautiful Soup是一个Python包,功能包括解析HTMLXML文档、修复含有未闭合标签等错误的文档(此种文档常被称为tag soup)。这个扩展包为待解析的页面建立一棵,以便提取其中的数据,这在网络数据采集时非常有用。[1]

      在2021年,Python 2.7的官方支持终止,BeautifulSoup发行版4.9.3是支持Python 2.7的最后版本[2]

      示例代码[编辑]

      #!/usr/bin/env python3
      # Anchor extraction from HTML document
      from bs4 import BeautifulSoup
      from urllib.request import urlopen
      with urlopen('https://en.wikipedia.org/wiki/Main_Page') as response:
          soup = BeautifulSoup(response, 'html.parser')
          for anchor in soup.find_all('a'):
              print(anchor.get('href', '/'))
      

      参见[编辑]

      参考资料[编辑]

      1. ^ 1.0 1.1 Beautiful Soup website. [18 April 2012]. (原始内容存档于2017-02-03). Beautiful Soup is licensed under the same terms as Python itself 
      2. ^ Richardson, Leonard. Beautiful Soup 4.10.0. beautifulsoup. Google Groups. 7 Sep 2021 [27 September 2022]. (原始内容存档于2022-09-29).