写在前面:
比较简单,就写的也很简单,爬取的内容是标题及热搜指数
import requests
from bs4 import BeautifulSoupurl = '=1&fr=topindex'
headers = {
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.82 Safari/537.36'}
r = (url, headers=headers, timeout=30)
r.encoding = r.apparent_encoding
soup = ,'html.parser')
title_list=soup.find_all(attrs={'class':'c-single-text-ellipsis'})
hot_list=soup.find_all(attrs={'class':'hot-index_1Bl1a'})
for j in range(len(title_list)):print(str((j+1)) + '.' + str(title_list[j].get_text())+'('+'热度指数'+':'+str(hot_list[j].get_text())+')')
本文发布于:2024-02-02 17:06:24,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170686478345226.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |