Python自动扫描出微信不是好友名单的方法
作者:Huny 发布时间:2023-03-14 09:25:44
标签:Python,自动扫描,微信好友
前言
最近找几个老友准备聊天发现几个已经被删除好友名单,做为潜水党多年的我已经不知道成为多少人的黑名单,但是好友列表却依然有不是好友的名单,面对庞大的好友数量想要清除谈何容易。虽然可以发消息给所有人,来识别是否是好友,但是毕竟打扰到了其他人,经过一番查询发现点击转账时会提示不是好友,这里只是点击转账并不是真的转账哦。做为一名技术潜水党,肯定要低调的办好事情。之前已经用appium玩过自动化了,那么这次就轻车熟路了。
准备
1.Appium环境搭建
环境搭建这里不再介绍,需要的可以看我之前的文章或者百度
2.手动操作流程图转自动操作流程图
最开始画的流程图,然后按照流程图去实现操作流程和逻辑。初步实现完成后进行调试,过程中不少逻辑不严谨的地方,以及一些框架自带的坑,最终总算可以一次性扫描了。但是其中还是存在个别的坑需要手动处理一下。暂时先记录下来,等以后看情况优化吧。
遇到暂停基本是聊天窗识别不到了,可以手动上滑一下,让程序识别下一个聊天窗口。需要先登陆微信号。
代码
from appium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
from selenium.common.exceptions import StaleElementReferenceException
# platformVersion = input('系统版本号(platformVersion): ')
# deviceName = input('设备名称(deviceName):')
desired_caps = {
"platformName": "Android", # 系统
"platformVersion": '10.0', # 系统版本号
# "platformVersion": platformVersion, # 系统版本号
"deviceName": 'b68548ed', # 设备名
# "deviceName": deviceName, # 设备名
"appPackage": "com.tencent.mm", # 包名
"appActivity": ".ui.LauncherUI", # app 启动时主 Activity
'unicodeKeyboard': True, # 使用自带输入法
'noReset': True # 保留 session 信息,可以避免重新登录
}
def is_element_exist(driver, by, value):
"""判断元素是否存在"""
try:
driver.find_element(by=by, value=value)
except Exception as e:
return False
else:
return True
def break_key(n):
"""点击返回按钮"""
for i in range(n):
el1 = wait.until(EC.element_to_be_clickable((By.ACCESSIBILITY_ID,"返回")))
el1.click()
def swipe_up():
"""向上滑动屏幕"""
# 获取屏幕的size
size = driver.get_window_size()
# 获取屏幕宽度 width
width = size['width']
# 获取屏幕高度 height
height = size['height']
x1 = width*0.5
y1 = height*0.45
y2 = height*0.3
driver.swipe(x1,y1,x1,y2,3000)
print("向上滑动")
if __name__ == '__main__':
driver = webdriver.Remote("http://localhost:4723/wd/hub", desired_caps)
# 设置等待
wait = WebDriverWait(driver, 300)
status = True
n = 2
count = 1
while status:
try:
# 点击通讯录
a1 = wait.until(EC.element_to_be_clickable(
(By.XPATH, "//android.widget.FrameLayout[@content-desc=\"当前所在页面,与的聊天\"]/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout[2]/android.view.ViewGroup/android.widget.FrameLayout[1]/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.LinearLayout/android.widget.RelativeLayout[2]/android.widget.LinearLayout/android.widget.RelativeLayout/android.widget.ImageView")))
a1.click()
#向上滑动
swipe_up()
if n < 13:
# 进入第一个聊天窗口,公众号为1,用户元素定位从2开始,一页最多12,每滑动屏幕从新开始到12.
g73 = wait.until(EC.element_to_be_clickable(
(By.XPATH, "//android.widget.FrameLayout[@content-desc='当前所在页面,与的聊天']/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout[2]/android.view.ViewGroup/android.widget.FrameLayout[1]/android.widget.FrameLayout/android.widget.FrameLayout/com.tencent.mm.ui.mogic.WxViewPager/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.ListView/android.widget.LinearLayout[%d]/android.widget.LinearLayout/android.widget.RelativeLayout/android.widget.LinearLayout/android.view.View"%(n))))
g73.click()
print("进入了第%d个好友聊天窗口"%(count))
count += 1
else:
n -= 1
g73 = wait.until(EC.element_to_be_clickable(
(By.XPATH, "//android.widget.FrameLayout[@content-desc='当前所在页面,与的聊天']/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout[2]/android.view.ViewGroup/android.widget.FrameLayout[1]/android.widget.FrameLayout/android.widget.FrameLayout/com.tencent.mm.ui.mogic.WxViewPager/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.ListView/android.widget.LinearLayout[%d]/android.widget.LinearLayout/android.widget.RelativeLayout/android.widget.LinearLayout/android.view.View"%(n))))
g73.click()
print("进入了第%d个好友聊天窗口"%(count))
count += 1
# 判断聊天窗是否有发送消息的元素
is_weichat = is_element_exist(driver, "id", "com.tencent.mm:id/ijq")
if is_weichat == True:
while True:
# # 有发消息则点击
wait.until(EC.element_to_be_clickable(
(By.ID, "com.tencent.mm:id/ijq"))).click()
print("点击了发消息")
#点击+号
is_jia = is_element_exist(driver, 'id', 'com.tencent.mm:id/ay7')
#判断是否有加号
if is_jia == True:
el4 = wait.until(EC.element_to_be_clickable((By.ID, "com.tencent.mm:id/ay7")))
el4.click()
print('点击+号')
#判断是否为转账
is_zhuanzhang = wait.until(EC.element_to_be_clickable((By.XPATH,"//android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.FrameLayout[1]/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout[2]/android.widget.RelativeLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.LinearLayout/android.view.ViewGroup/android.widget.GridView/android.widget.LinearLayout[6]/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.TextView")))
if is_zhuanzhang.text == "转账":
# is_zhuanzhang = is_element_exist(driver, 'xpath', '//android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.FrameLayout[1]/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout[2]/android.widget.RelativeLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.LinearLayout/android.view.ViewGroup/android.widget.GridView/android.widget.LinearLayout[6]/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.TextView')
# if is_zhuanzhang == True:
#点击转账
el5 = wait.until(EC.element_to_be_clickable((By.XPATH,"//android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.FrameLayout[1]/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout[2]/android.widget.RelativeLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.LinearLayout/android.view.ViewGroup/android.widget.GridView/android.widget.LinearLayout[6]/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.RelativeLayout/android.widget.ImageView[2]")))
el5.click()
print('点击转账')
#输入金额0.01
el6 = wait.until(EC.element_to_be_clickable((By.ID,"com.tencent.mm:id/jf4")))
el6.send_keys("0.01")
print('输入金额')
#点击确认转账
el7 = wait.until(EC.element_to_be_clickable((By.ID,"com.tencent.mm:id/e6c")))
el7.click()
print('点击确认转账')
time.sleep(2)
#判断是否有知道了
is_not_friend = is_element_exist(driver,'id','com.tencent.mm:id/ffp')
if is_not_friend == True:
#点击知道了
el8 = wait.until(EC.element_to_be_clickable((By.ID,"com.tencent.mm:id/ffp")))
el8.click()
print('点击知道了')
#获取用户名称并打印
el9 = wait.until(EC.element_to_be_clickable((By.ID,"com.tencent.mm:id/h2k")))
print('不是好友的微信名称为:',el9.text)
with open('weixin.txt','a+')as f:
f.write('不是好友的微信名称:' + el9.text + '\n')
driver.keyevent(4)
driver.keyevent(4)
driver.keyevent(4)
driver.keyevent(4)
print('返回')
n += 1
break
else:
#没有知道则返回
driver.keyevent(4)
break_key(2)
n += 1
print('返回')
break
else:
#没有转账则返回到首页
driver.keyevent(4)
driver.keyevent(4)
print('返回')
n += 1
break
else:
#没有+号则返回到首页
driver.keyevent(4)
driver.keyevent(4)
print('返回')
n += 1
break
except StaleElementReferenceException:
print('捕获StaleElementReferenceException异常')
这里已经扫描到200多个好友了,其中可能需要手动上滑一下
不是好友的名单会在当前目录生成一个txt文件进行保存
偶然出现几个异常,不知道是什么原因
总的来说功能基本都已经实现了,还有细节问题后面看情况优化吧
来源:https://www.cnblogs.com/huny/p/14788006.html


猜你喜欢
- 这是官方对SubFolders的介绍:返回由指定文件夹中所有子文件夹(包括隐藏文件夹和系统文件夹)组成的 Folders 集合。object
- 在编写代码时我们有时候会碰到需要自己解析四则运算表达式的情况,本文简单的介绍使用JavaScript实现对简单四则运算表达式的解析。一、熟悉
- 一、缺失数据剔除1. python 方式获取所有的缺失值,返回一个 true 和 false 的表df.isnull()统计缺失值,按照每一
- 1、静态网页与动态比较: 1)静态网页: 优势:A、 对搜索引擎友好,被收录的质量高;B、访问速度快;C、资源(cpu 等)占用少。 劣势:
- 远程服务器配置可以使得数据库管理员在服务器以外的主机上连接到一个SQL Server实例,以便管理员在没有建立单据连接的情况下在其他的SQL
- Dump ALL MySQL Databasesmysqldump --user=XXXXXXXX --password=XXXXXXX -
- getpwname只能得到gid一个username。import pwdmyGroupId = pwd.getpwnam(username
- 直接上代码:# -*- coding: utf-8 -*- import Queue import threadingimport urll
- 原理:print() 函数会把内容放到内存中, 内存中的内容并不一定能够及时刷新显示到屏幕中(应该是要满足某个条件,这个条件现在还不清楚)。
- 看书笔记db file scattered read DB ,db file sequential read DB,free buffer
- 目录1. 配置Python环境变量2. 安装Python编辑器,并在其中配置Python3. 安装控制包uiautomator2,和其它辅助
- 主要应用了argsort()函数,函数原型:numpy.argsort(a, axis=-1, kind='quicksort
- 本文实例讲述了Python计算三维矢量幅度的方法。分享给大家供大家参考。具体如下:from numpy import *from math
- 本文介绍了vue语法之拼接字符串的示例代码,分享给大家,具体如下。先来一行代码:<div class="swiper-sli
- 一 . 得到这个对象的实例Connection con ;con = DriverManager.getConnection(url,use
- 注意:myemployees库和shoppingCart库在同一台物理主机,如果不在同一台物理主机该怎么办呢?下面我会介绍到。情况一2个库在
- 方法一:使用列表推导式>>> vec = [[1,2,3],[4,5,6],[7,8,9]]>>> ge
- 做服务器端开发的同学应该都对进程监控不会陌生,最近恰好要更换 uwsgi 为 gunicorn,而gunicorn又恰好有这么一章讲进程监控
- 众所周知,vue可以用来开发移动端app,可以使用hbuilder将build好的vue打包成一个移动端app,但是用过之后就会发现,使用c
- 哥德巴赫猜想:大于8的偶数之和都可以被两个素数相加范围 8 - 10000思路:首先不要去管需要什么什么东西实现,所以我们如果知道如何去完成