其他分享
首页 > 其他分享> > 爬取微博热搜榜

爬取微博热搜榜

作者:互联网

import requests
from bs4 import BeautifulSoup
url = 'https://s.weibo.com/top/summary?cate=realtimehot'
headers = {'User-Agent':'Mozilla/5.0 (Windows NT 6.3; Win64; x64)'
                  'AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36'}
urls = requests.get(url, headers=headers)
urls.encoding = urls.apparent_encoding
text = urls.text
soup = BeautifulSoup(text, 'lxml')
a = soup.find_all(class_="td-02")
b = [i.get_text() for i in a]
print('热搜榜')
print('{:25}'.format('标题(搜索数)'))
for i,y in zip(b,a):
   print('{:10}\t{}\n'.format(i,y))

 

标签:format,text,搜榜,爬取,headers,537.36,urls,print,微博热
来源: https://www.cnblogs.com/zyy-k/p/12539701.html