python网络爬虫与信息提取——4.Beautiful Soup库入门
1.Beautiful Soup库的安装 Win平台: “以管理员身份运行”cmd执行 pip install beautifulsoup4 from bs4 import BeautifulSoup 导入以缩写bs4为库名 2.soup = BeautifulSoup('需要解析的html代码', 'html.parser解析器') 3.beautifulsoup库的基本元素 BeautifulSoup对应一个HTML/XML文档的全部内容 (1)Beautiful Soup库解析器 bs4的HTML解析器 BeautifulSoup(mk,'html.parser') 安装bs4库 lxml的HTML解析器 BeautifulSoup(mk,'lxml') pip install lxml lxml的XML解析器 BeautifulSoup(mk,'xml') pip install lxml html5lib的解析器 BeautifulSoup(mk,'html5lib') pip install html5lib (2)BeautifulSoup类的基本元素 Tag 标签,最基本的信息组织单元,分别用<>和</>标明开头和结尾 Name 标签的名字,<p>…</p>的名字是'p',格式:<tag>.name Attributes 标签的属性,字典形式组织,格式:<tag>