百度实时热点爬取
#>>>>>>>>>>>>>>>>>>>>>>>百度頭條實時熱點爬取
#>>>>>>>>>>>>>>>>>>>>>>>百度頭條實時熱點爬取from bs4 import BeautifulSoup import requests import time from fake_useragent import UserAgent#偽造一個 UserAgent 賦值給use use = UserAgent().chromeurl = 'http://top.baidu.com/buzz?b=1&c=513&fr=topbuzz_b341_c513' headers = {'User-Agent':use}#發起請求,請求源碼, 轉碼 response = requests.get(url,headers = headers) response.encoding = response.apparent_encoding #因為輸出的不是中文,所以要轉換編碼格式 html = response.text#調用bs4解析網頁,把所有的tr標簽全部匹配 soup = BeautifulSoup(html,'lxml') masgs = soup.find_all('tr')[1:] # print(masgs)#遍歷獲得每個需要的信息 for td in masgs:ranking1 = td.find_all(class_="num-top") #排名 #前三ranking2 = td.find_all(class_="num-normal") #除去前三 class_="num-normal"content = td.find_all(class_="list-title") #文案head = td.find_all(class_="icon-rise") #熱度href = td.find_all('a',attrs={'class':"list-title",'target':"_blank"}) # 信息的跳轉hreffor rank1,content,head,href in zip(ranking1,content,head,href):data1={'rand': rank1.get_text(),'content':content.get_text(),'head':int(head.get_text()),'href':href['href']}# print(data1)for rank2,content,head,href in zip(ranking2,content,head,href):data2={'rand': rank2.get_text(),'content':content.get_text(),'head': int(head.get_text()),'href':href['href']}print(data2)總結
- 上一篇: 图像校正-仿射图像的畸变校正
- 下一篇: 计算机组成原理(谭志虎)第7章课后题部分