老规矩,先学会安装:
方式:pip install beautifulsoup4
测试是否安装成功:
import requests
r = requests.get("链接")
demo = r.text
form bs4 import BeautifulSoup
soup = BeautifulSoup(demo, "html.parser")实例案例演示:
html = bs4.BeautifulSoup(response.text, features='lxml')
note_list = html.find_all('ul', class_='note-list', limit=1)[0]
for a in note_list.select('li>div.content>a.title'):
title = a.contents[0]
link = f'链接{a["href"]}'
print(f'《{title}》,{link}')