标签:parent apple last code safari div lxml app taf
import requests from bs4 import BeautifulSoup import bs4 import pandas as pd url = ‘http://top.baidu.com/buzz?b=341&c=513&fr=topbuzz_b1‘ headers = {‘User-Agent‘:‘Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36‘}# r=requests.get(url,timeout=30,headers=headers) r.encoding=r.apparent_encoding t=r.text soup=BeautifulSoup(t,‘lxml‘) a=[] b=[] for i in soup.find_all(class_="keyword"): a.append(i.get_text().strip()) for j in soup.find_all(‘td‘, class_="last"): b.append(j.get_text().strip()) data=[a,b] c=pd.DataFrame(data,index=["标题","热度"]) print(c.T)
登录网站,管理员工具查看源代码
标签:parent apple last code safari div lxml app taf
原文地址:https://www.cnblogs.com/jlt965256450/p/12492435.html