BeautifulSoup
from bs4 import BeautifulSoup
soup = BeautifulSoup("<html>data</html>", 'html.parser')
soup2 = BeautifulSoup(open("D://demo.html"), 'html.parser')
- Beautiful Soup 的解析器
解析器 | 使用方法 | 条件 |
---|---|---|
bs4 的HTML解析器 | BeautifulSoup(mk,‘html.parser’) | 安装bs4库 |
lxml的HTML解析器 | BeautifulSoup(mk,‘lxml’) | pip sinstall lxml |
lxml的XML解析器 | BeautifulSoup(mk,‘xml’) | pip install lxml |
html5lib 的解析器 | BeautifulSoup(mk,‘html5lib’) | pip install html5lib |
- Beautiful Soup 的基本元素
[例一]
>>> import requests
>>>