百度热搜
Posted python-kp
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了百度热搜相关的知识,希望对你有一定的参考价值。
# -*- coding:utf-8 -*- import requests from bs4 import BeautifulSoup url = "http://top.baidu.com/buzz?b=1&fr=topindex" header = { "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (Khtml, like Gecko) Chrome/83.0.4103.106 Safari/537.36", } content = [] r = requests.get(url,headers = header) respond = r.text soup = BeautifulSoup(respond,"html.parser") # HotSearchs = soup.find_all("td",class_="keyword") # HotSearchs = soup.select("td[class=‘keyword‘]") HotSearchs = soup.find_all("tr")[1:] for HotSearch in HotSearchs: if HotSearch.find(class_ ="list-title") != None: title = HotSearch.find(class_ = "list-title").text.encode("iso-8859-1").decode("gbk") number = HotSearch.find(class_ = "last").text.strip() content.append([title,number]) print(content)
以上是关于百度热搜的主要内容,如果未能解决你的问题,请参考以下文章