forked from 404name/CTGU-Automatic-safety-report
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path微博热搜.py
45 lines (37 loc) · 1.49 KB
/
微博热搜.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# https://s.weibo.com/top/summary/
import requests
from bs4 import BeautifulSoup
import lxml
def wb():
news = []
# 新建数组存放热搜榜
hot_url = 'https://s.weibo.com/top/summary/'
# 热搜榜链接
r = requests.get(hot_url, timeout=None)
# 向链接发送get请求获得页面
soup = BeautifulSoup(r.text, 'lxml')
# 解析页面
urls_titles = soup.select(
'#pl_top_realtimehot > table > tbody > tr > td.td-02 > a')
hotness = soup.select(
'#pl_top_realtimehot > table > tbody > tr > td.td-02 > span')
# for i in range(len(urls_titles)-1):
hot_news = "【微博每日热搜爬虫0v0】\n"
for i in range(10):
# 将信息保存到字典中
hot_news += '[' + str(i+1) + '] :' + \
urls_titles[i+1].get_text() + '\n'
# get_text()获得a标签的文本
# hot_news['url'] = "https://s.weibo.com"+urls_titles[i]['href']
# ['href']获得a标签的链接,并补全前缀
# hot_news['hotness'] =
# 获得热度文本
# 字典追加到数组中
hot_news += "———————————\n"
hot_news += "我是Qmsg酱消息机器人喔\n"
return hot_news
def sentMsg(msg):
headers = {'Content-Type': 'application/json;charset=utf-8'}
api_url = "https://qmsg.zendee.cn/send/49bdb9375842537a41ebc635a09229b2?msg= %s" % msg
return requests.post(api_url, headers=headers, timeout=None).content
sentMsg(wb())