可以利用 pip 来安装:
pip install beautifulsoup4
源代码:
import requests
r = requests.get("https://python123.io/ws/demo.html")
r.text
demo = r.text
from bs4 import BeautifulSoup
soup = BeautifulSoup(demo , "html.parser")
print(soup.prettify())
原网页,右键查看源代码:
利用爬虫执行之后:
可以看到树形的代码结构!