一、打开微信电脑版

二、找到通讯录页面

三、全屏通讯录页面

四、新建xxx.py的文件

1.复制如下内容,并运行程序

import win32api
import ctypes
import time
import random
rand_time=random.uniform(0,1)
# 和所有的公众号说再见,包括我自己的公众号!~
# 定义鼠标左侧单击函数
def left_press(x, y, button=1):
    buttonAction = 2 ** ((2 * button) - 1)
    win32api.mouse_event(buttonAction, x, y)
# 定义鼠标左侧单击释放函数
def left_release(x, y, button=1):
    buttonAction = 2 ** ((2 * button))
    win32api.mouse_event(buttonAction, x, y)    
# 定义鼠标右侧单击函数
def right_press(x, y, button=2):
    buttonAction = 2 ** ((2 * button) - 1)
    win32api.mouse_event(buttonAction, x, y)
# 定义鼠标右侧单击释放函数
def right_release(x, y, button=2):
    buttonAction = 2 ** ((2 * button))
    win32api.mouse_event(buttonAction, x, y)   
# 定义鼠标移动函数
def move(x, y):
    ctypes.windll.user32.SetCursorPos(x, y)
# 最小化程序运行的窗体,并且移动到LOGO的显示坐标位置
# (1180,15)程序运行的窗体坐标位置
# 移动到坐标
time.sleep(1)
move(x=1180,y=15)
# 休眠1s
time.sleep(rand_time)
# 点击
left_press(x=1180,y=15)
# 释放鼠标左键
left_release(x=1180,y=15)
for i in range(30):
    # (613,173)公众号LOGO的坐标位置
    time.sleep(rand_time)  
    move(613,120)
    right_press(613,120)
    right_release(613,120)
    # 左击“取消关注”
    time.sleep(rand_time)  
    move(633,185)
    left_press(633,185)
    left_release(633,185)
    # 点击确定
    time.sleep(rand_time)  
    move(700,430)
    left_press(700,430)
    left_release(700,430)

2.默认循环30次,也就是取消30个公众号。如果想要自定义个数,可以用这个代码

import win32api
import ctypes
import time
import random
numbers=input("请输入取消的公众号次数:")
rand_time=random.uniform(0,1)
# 和所有的公众号说再见,包括我自己的公众号!~
# 定义鼠标左侧单击函数
def left_press(x, y, button=1):
    buttonAction = 2 ** ((2 * button) - 1)
    win32api.mouse_event(buttonAction, x, y)
# 定义鼠标左侧单击释放函数
def left_release(x, y, button=1):
    buttonAction = 2 ** ((2 * button))
    win32api.mouse_event(buttonAction, x, y)    
# 定义鼠标右侧单击函数
def right_press(x, y, button=2):
    buttonAction = 2 ** ((2 * button) - 1)
    win32api.mouse_event(buttonAction, x, y)
# 定义鼠标右侧单击释放函数
def right_release(x, y, button=2):
    buttonAction = 2 ** ((2 * button))
    win32api.mouse_event(buttonAction, x, y)   
# 定义鼠标移动函数
def move(x, y):
    ctypes.windll.user32.SetCursorPos(x, y)
# 最小化程序运行的窗体,并且移动到LOGO的显示坐标位置
# (1180,15)程序运行的窗体坐标位置
# 移动到坐标
time.sleep(1)
move(x=1180,y=15)
# 休眠1s
time.sleep(rand_time)
# 点击
left_press(x=1180,y=15)
# 释放鼠标左键
left_release(x=1180,y=15)
for i in range(numbers):
    # (613,173)公众号LOGO的坐标位置
    time.sleep(rand_time)  
    move(613,120)
    right_press(613,120)
    right_release(613,120)
    # 左击“取消关注”
    time.sleep(rand_time)  
    move(633,185)
    left_press(633,185)
    left_release(633,185)
    # 点击确定
    time.sleep(rand_time)  
    move(700,430)
    left_press(700,430)
    left_release(700,430)

五、操作演示

六、特别说明

1.我的电脑是1920x1080分辨率,所以上述的坐标也只对这个分辨率起作用
2.运行程序时,保证通讯录页面全屏且在VSCODE程序的下面
3.代码写的很烂,主要不是科班出身,还需要加倍努力!

标签: WIN, Python, 批量取消公众号

已有 6 条评论

  1. hhh hhh

    学习了

    1. 一个学金融的文史哲小生 一个学金融的文史哲小生

      ?里玩?

  2. 一个学金融的文史哲小生 一个学金融的文史哲小生

    我确实是把Python当按键精灵用了

  3. 廾匸 廾匸

    ( ̄▽ ̄) 好亲民的功能

  4. 廾匸 廾匸

    ( ̄▽ ̄) 好方便

添加新评论