码迷,mamicode.com
首页 > 其他好文 > 详细

爬去百度热搜榜

时间:2020-03-22 01:25:54      阅读:70      评论:0      收藏:0      [点我收藏+]

标签:code   web   rom   百度   taf   使用   打开   img   ISE   

1.打开网站http://top.baidu.com/buzz?b=1&fr=topindex

2.右键找到源代码

技术图片

 3.用工具爬取数据

import requests
from bs4 import BeautifulSoup
import pandas as pd
titles=[]
hots=[]
url=‘http://top.baidu.com/buzz?b=1&fr=topindex‘#百度今日热搜
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.raise_for_status()
r.encoding = r.apparent_encoding
html = r.text
table = BeautifulSoup(html,"html.parser").find("table")
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)

 

4.爬取的数据为

技术图片

 

爬去百度热搜榜

标签:code   web   rom   百度   taf   使用   打开   img   ISE   

原文地址:https://www.cnblogs.com/xx1129/p/12543514.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!