前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >ChatGPT帮我获取知乎热点的代码

ChatGPT帮我获取知乎热点的代码

原创
作者头像
用户10443079
发布2023-04-23 15:02:47
5020
发布2023-04-23 15:02:47
举报
文章被收录于专栏:测试技术干活

帮我写获取知乎热点的代码

import requests

from bs4 import BeautifulSoup

url = 'https://www.zhihu.com/hot'

res = requests.get(url)

soup = BeautifulSoup(res.text, 'html.parser')

hot_list = soup.find_all('div', class_='HotItem-content')

for hot in hot_list:

title = hot.find('h2').text.strip()

excerpt = hot.find('p').text.strip()

metrics = hot.find_all('div', class_='HotItem-metrics')[0]

likes = metrics.find_all('div')[0].text.strip()

comments = metrics.find_all('div')[1].text.strip()

shares = metrics.find_all('div')[2].text.strip()

print(f'{title}:{excerpt}\n点赞数:{likes},评论数:{comments},分享数:{shares}\n')

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档