符伟鹏

导航

Python高级应用第5次作业---网络爬虫练习---百度搜索风云榜

百度搜索风云榜的爬取

首先进入网站http;//top.baidu.com/

对其进行分析

 

 

 

 

import requests
from bs4 import BeautifulSoup
import pandas as pd
titles=[]
hots=[]
url='http://top.baidu.com/'
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)
r.encoding = r.apparent_encoding
html = r.text
table = BeautifulSoup(html,"html.parser").find("div")
soup=BeautifulSoup(html,'lxml')
for m in soup.find_all(class_="list-title"):
titles.append(m.get_text().strip())
for n in soup.find_all(class_="icon-rise"):
hots.append(n.get_text().strip())
final=[titles,hots]
print(final)
s=pd.DataFrame(final,index=["标题","搜索指数"])
print(s.T)

 

posted on 2020-03-21 01:16  符伟鹏  阅读(381)  评论(0编辑  收藏  举报