帮我写获取知乎热点的代码
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 删除。