爬取百度前20个热搜

Posted jlwlhahaha

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了爬取百度前20个热搜相关的知识,希望对你有一定的参考价值。

import requests
from bs4 import BeautifulSoup
import bs4
import pandas as pd
url = ‘http://top.baidu.com/buzz?b=341&c=513&fr=topbuzz_b341_c513‘
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
soup=BeautifulSoup(html,‘lxml‘)
a=[]
b=[]
for link1 in soup.find_all(class_=‘list-title‘):
    a.append(link1.get_text())
for link2 in soup.find_all(‘td‘,class_=‘last‘):
    b.append(link2.get_text().strip())
data=pd.DataFrame([a,b],index=["关键词","搜索指数"]).T
print("爬取百度热搜榜前十:"," ")
print(data.iloc[0:20])

技术图片

 

以上是关于爬取百度前20个热搜的主要内容,如果未能解决你的问题,请参考以下文章

爬取百度热搜榜

百度热搜数据爬取及分析

爬取百度热搜榜

爬取百度热搜榜前十

python网络爬虫:实现百度热搜榜数据爬取

爬去百度热搜榜