微信发送新闻每日汇报
运行代码的时候要打开微信o
# coding=utf8 import pyautogui import pyperclip import time import requests from lxml import etree def get_requests(): headers = { 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36'} html = requests.get('https://www.163.com/dy/media/T1603594732083.html', headers=headers) tree = etree.HTML(html.text) src = tree.xpath('//div[@class="desc"]//a/@href') html = requests.get(src[0], headers=headers) tree = etree.HTML(html.text) contents = tree.xpath('//p[@id][1]/text()') return contents def open_txt(): with open('./daily_report.txt', 'w') as f: text = get_requests() # print(type(str(text[0]))) for i in text: article = str(i) f.write(article) f.write('\n') def get_msg(): try: open_txt() except: print("") """发送文本里的信息""" with open('./daily_report.txt') as f: contents = f.read() f.close() return contents def send(msg): # 复制需要发送的内容到粘贴板 pyperclip.copy(msg) # 模拟键盘 ctrl + v 粘贴内容 pyautogui.hotkey('ctrl', 'v') # 发送消息 pyautogui.press('enter') def send_msg(friend, m): if m == 1: # Ctrl + alt + w 打开微信 pyautogui.hotkey('ctrl', 'alt', 'w') # 搜索好友 pyautogui.hotkey('ctrl', 'f') # 复制好友昵称到粘贴板 pyperclip.copy(friend) # 模拟键盘 ctrl + v 粘贴 pyautogui.hotkey('ctrl', 'v') time.sleep(1) # 回车进入好友消息界面 pyautogui.press('enter') # 发送消息 send(get_msg()) def send_friends(): m = 1 for i in friend_name: send_msg(i, m) time.sleep(1) m = m + 1 if __name__ == '__main__': # 填写发送好友的名字,用'\n'隔开,可发送多个人 friend_name = '文件传输助手' \ '\nMiYol' friend_name = friend_name.split('\n') send_friends()
本文作者:MiYol
本文链接:https://www.cnblogs.com/miyol/p/16721417.html
版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步