用jupyter爬取微博热搜的代码
时间: 2023-08-04 13:31:57 浏览: 116
python数据可视化分析2021微博热搜(.ipynb请用jupyter打开)
5星 · 资源好评率100%
好的,以下是一个在jupyter中爬取微博热搜的代码:
```python
import requests
from bs4 import BeautifulSoup
url = 'https://s.weibo.com/top/summary?cate=realtimehot'
response = requests.get(url)
soup = BeautifulSoup(response.text, 'html.parser')
hot_list = soup.select('.list_a > tr')
for hot in hot_list:
rank = hot.select_one('.td-01.ranktop').text.strip()
title = hot.select_one('.td-02 > a').text.strip()
heat = hot.select_one('.td-02 > span').text.strip()
print(rank, title, heat)
```
将代码复制粘贴到jupyter中的代码单元格中,执行即可。
阅读全文