实时检测全国已公布的肺炎地区

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2020-01-22 19:23
# @Author  : Anthony
# @Email   : [email protected]
# @File    : check_feiyan_health.py

# 定时检测全国已公布的肺炎地区

import requests
from lxml import etree
import itchat
message_list = [] def SendChatRoomsMsg(gname,context): myroom = itchat.get_chatrooms(update=True) global username myroom = itchat.search_chatrooms(name=gname) for room in myroom: if room['NickName'] == gname: username = room['UserName'] itchat.send_msg(context,username) else: print('No groups found') def dingxiangcrawler(url): headers = { # 请求身份/默认为User-Agent:python 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.87 Safari/537.36', } responses = requests.get(url=url, headers=headers).content response = str(responses,'utf-8') html = etree.HTML(response) messages1 = html.xpath("//div[@class='mapTop___2VZCl']/p") messages2 = html.xpath("//div[@class='descBox___3dfIo']/p") for msg1 in messages1: city1 = msg1.xpath('.//text()')[0] message_list.append(city1) for msg2 in messages2: city2 = msg2.xpath('.//span/text()')[0] message_list.append(city2) url = "https://3g.dxy.cn/newh5/view/pneumonia?sr=1&nm=lcyy&dt=20200121&pd=dxyer&from=groupmessage&isappinstalled=0" dingxiangcrawler(url) gname = '2020致富群' # 填写需要发送的群名称 context = '''''' for i in message_list: context += i+'\n' itchat.auto_login(enableCmdQR=True,hotReload=True) SendChatRoomsMsg(gname,context) itchat.run()

  

猜你喜欢

转载自www.cnblogs.com/ipyanthony/p/12229644.html