ipyanthony

 

 

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2020-01-22 19:23
# @Author  : Anthony
# @Email   : ianghont7@163.com
# @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()

  

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2022-01-18
  • 2021-06-02
  • 2021-07-31
  • 2021-04-13
  • 2021-08-03
  • 2021-06-27
猜你喜欢
  • 2021-06-04
  • 2021-10-12
  • 2021-12-12
  • 2021-07-08
  • 2021-05-25
  • 2021-12-08
  • 2021-11-26
相关资源
相似解决方案