知乎热搜榜

复制代码
import requests#获得请求
 2 from bs4 import BeautifulSoup#解析的第三方库
 3 import pandas as pd
 5 url = 'http://top.zhihu.com/buzz.php?p=top10&tdsourcetag=s_pctim_aiomsg&qq-pf-to=pcqq.c2c?'
 6 kv = {'user-agent': 'Mozilla/5.0'}#伪装爬虫
 7 respond = requests.get(url,timeout = 30,headers=kv)
 8 r.raise_for_status()
 9 r.encoding = r.apparent_encoding
10 r.text#获取源代码
11 html=r.text
12 soup=BeautifulSoup(html,'html.parser')
13 #解析网页,提取内容
14 q = []#创建空列表
15 w = []
16 for x in soup.find_all(class_="list-title")[:10]:
17     q.append(x.get_text().strip())
18 for y in soup.find_all(class_="icon-rise")[:10]:
19     w.append(y.get_text().strip())
20 text =['q,w']
21 print(text)
22 c=pd.DataFrame(text,index=['标题','热度'])
23 print(new file)
复制代码

 

 

 

posted @   张福祥  阅读(947)  评论(0编辑  收藏  举报
编辑推荐:
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
阅读排行:
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
点击右上角即可分享
微信分享提示