• 企业400电话
  • 网络优化推广
  • AI电话机器人
  • 呼叫中心
  • 全 部 栏 目

    网站建设 商标✡知产 微网小程序 电商运营 彩铃•短信 增值拓展业务
    python实现半自动化发送微信信息
    POST TIME:2021-10-18 13:09

    本文实例为大家分享了python半自动化发送微信信息的具体代码,供大家参考,具体内容如下

    相关第三方库

    1.pyautogui
    自动操作鼠标、键盘的第三方库

    2.pyperclip
    用于将文本复制和粘贴到剪贴板

    3.requests
    HTTP第三方库

    4.psutil
    可以查看系统信息,进程、CPU等

    5.腾讯地图API
    因为我想实现发送定位,所以需要用

    总体思路

    1.先手动登录微信

    2.使用os模块调用微信进程

    3.使用pyautogui模块来自动操作微信的快捷键,实现搜索好友、发送信息,pyperclip模块用来复制需要发送的中文

    4.使用requests模块来调用腾讯地图的API

    具体代码

    # -*- coding: utf-8 -*
    import sys
    
    import psutil
    import pyautogui
    import time
    import os
    import pyperclip
    import json
    import requests
    
    
    def main():
        # 先确认是否登录微信
        confirms = pyautogui.confirm("微信已登录?", "请先登录微信!")
        if confirms == "Cancel":
            sys.exit()
        get_wechat()
        find_friend()
        msg = locate()
        # 发送内容
        send(msg)
    
    
    # 定位
    def locate():
        url = "https://apis.map.qq.com/ws/location/v1/ip?key=自己申请的key"
        session = requests.Session()
        # 取消代理
        session.trust_env = False
        resp = session.get(url)
        print(resp.json())
        adress = resp.json()
        print(adress["result"]["location"])
        # 获取到经纬度
        point = adress["result"]["location"]
        # 由经纬度获取定位
        pointUrl = "https://apis.map.qq.com/uri/v1/geocoder?coord=" + str(point["lat"]) + "," + str(
            point["lng"]) + "referer=自己申请的key"
        print(pointUrl)
        return pointUrl
    
    
    def find_friend():
        pyautogui.hotkey("ctrl", "f")
        pyautogui.hotkey("ctrl", "a")
        pyautogui.hotkey("delete")
        content = pyautogui.prompt("请输入好友名:")
        if content is None:
            sys.exit()
        pyperclip.copy(content)
        pyautogui.hotkey("ctrl", "v")
        pyautogui.hotkey("enter")
    
    
    def send(msg):
        pyperclip.copy(msg)
        pyautogui.hotkey("ctrl", "v")
        pyautogui.hotkey("enter")
    
    
    # 查找进程
    def get_wechat():
        flag = False
        pids = psutil.process_iter()
        for p in pids:
            if p.name() == "WeChat.exe":
                flag = True
                print(p.name())
                print(p.exe())
                os.system(p.exe())
                break
            else:
                continue
        if not flag:
            pyautogui.alert("请先登录微信!")
    
    
    if __name__ == '__main__':
        pyautogui.FAILSAFE = True
        pyautogui.PAUSE = 0.2
        main()

    不足之处

    1、发送定位,发送的只能是一个链接,没有实现手机微信定位所实现的可预览的效果
    2、搜索好友时,没有辨别输入的是例如聊天内容等其他东西,所以需要用户确保自己输入的是好友名

    以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

    您可能感兴趣的文章:
    • 易语言修改快捷方式进行微信多开的代码
    • 利用Python读取微信朋友圈的多种方法总结
    • Android实现微信登录的示例代码
    • Flutter实现微信朋友圈功能
    • 今天办公室海王小姐姐悄悄问我怎么在PC端登录多个微信号
    上一篇:运用Python3实现Two-Pass算法检测区域连通性
    下一篇:pytorch 搭建神经网路的实现
  • 相关文章
  • 

    关于我们 | 付款方式 | 荣誉资质 | 业务提交 | 代理合作


    © 2016-2020 巨人网络通讯

    时间:9:00-21:00 (节假日不休)

    地址:江苏信息产业基地11号楼四层

    《增值电信业务经营许可证》 苏B2-20120278

    X

    截屏,微信识别二维码

    微信号:veteran88

    (点击微信号复制,添加好友)

     打开微信