BeautifulSoup入门

BeautifulSoup入门

Beautiful Soup Documentation
[2.7]–Beautifulsoup解析Html的实例演示_哔哩哔哩_bilibili

Beautiful Soup 4.4.0 文档 — Beautiful Soup 4.2.0 documentation

安装

1
2
3
4
5
6
pip install beautifulsoup4
pip install beautifulsoup4 -i https://pypi.tuna.tsinghua.edu.cn/simple/
pip install lxml -i https://pypi.tuna.tsinghua.edu.cn/simple/
//使用
import bs4
from bs4 import BeautifulSoup
1
2
3
4
5
6
7
from bs4 import BeautifulSoup
with open("./html/liubei.html", 'r', encoding='utf-8') as fin:
    html_doc = fin.read()
soup = BeautifulSoup(html_doc,"html.parser")
links = soup.find_all("a")
for link in links:
    print(link.name)