前言

最近找几个老友准备聊天发现几个已经被删除好友名单,做为潜水党多年的我已经不知道成为多少人的黑名单,但是好友列表却依然有不是好友的名单,面对庞大的好友数量想要清除谈何容易。虽然可以发消息给所有人,来识别是否是好友,但是毕竟打扰到了其他人,经过一番查询发现点击转账时会提示不是好友,这里只是点击转账并不是真的转账哦。做为一名技术潜水党,肯定要低调的办好事情。之前已经用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文件进行保存



偶然出现几个异常,不知道是什么原因



总的来说功能基本都已经实现了,还有细节问题后面看情况优化吧

Python自动扫描出微信不是好友名单的更多相关文章

  1. python 脚本查看微信把你删除的好友--win系统版

    PS:目测由于微信改动,该脚本目前不起作用 下面截图来自原作者0x5e 相信大家在微信上一定被上面的这段话刷过屏,群发消息应该算是微信上流传最广的找到删除好友的方法了.但群发消息不仅仅会把通讯录里面所 ...

  2. 我用 Python 爬取微信好友,最后发现一个大秘密

    前言 你身处的环境是什么样,你就会成为什么样的人.现在人们日常生活基本上离不开微信,但微信不单单是一个即时通讯软件,微信更像是虚拟的现实世界.你所处的朋友圈是怎么样,慢慢你的思想也会变的怎么样.最近在 ...

  3. 10分钟教你用Python玩转微信之好友性别比例统计分析

    01 前言+效果展示 想必,微信对于大家来说,是再熟悉不过的了.那么,大家想不想探索一下微信上的各种奥秘呢?今天,我们一起来简单分析一下微信上的好友性别比例吧~废话不多说,开始干活. 结果如下: 02 ...

  4. 我用 Python 找出了删除我微信的所有人并将他们自动化删除了

    1. 概述 不知你是否遇到过在微信上给通讯录中的某个人发消息,结果出现了这一幕: 平时一直认为自己的心里素质过硬,不过遇到这种情况 ... 在我缓了半个钟头(半分钟)之后,缓缓拿出了手机,打开微信,找 ...

  5. 全网最全的Windows下Anaconda2 / Anaconda3里Python语言实现定时发送微信消息给好友或群里(图文详解)

    不多说,直接上干货! 缘由: (1)最近看到情侣零点送祝福,感觉还是很浪漫的事情,相信有很多人熬夜为了给爱的人送上零点祝福,但是有时等着等着就睡着了或者时间并不是卡的那么准就有点强迫症了,这是也许程序 ...

  6. 10分钟教你用Python玩转微信之抓取好友个性签名制作词云

    01 前言+展示 各位小伙伴我又来啦.今天带大家玩点好玩的东西,用Python抓取我们的微信好友个性签名,然后制作词云.怎样,有趣吧~好了,下面开始干活.我知道你们还是想先看看效果的. 后台登录: 词 ...

  7. python 爬取微信好友列表和个性签名,绘制个性签名云图

    python爬取微信好友列表和个性签名,绘制个性签名云图 1. 简要介绍 本次实验主要用到下面几个库 : 1)itchat---用于微信接口,实现生成QR码,用于微信扫描登陆 2)re(正则化)--- ...

  8. 用Python玩转微信(一)

    欢迎大家访问我的个人网站<刘江的博客和教程>:www.liujiangblog.com 主要分享Python 及Django教程以及相关的博客 交流QQ群:453131687 今天偶然看见 ...

  9. Python+Django实现微信扫码支付流程

    Python+Django实现微信扫码支付流程 关注公众号"轻松学编程"了解更多. 获取源码可以加我微信[1257309054],文末有二维码. [微信公众号支付官网]https: ...

随机推荐

  1. CF524F And Yet Another Bracket Sequence 题解

    题目链接 算法:后缀数组+ST表+贪心   各路题解都没怎么看懂,只会常数巨大的后缀数组+ST表,最大点用时 \(4s\), 刚好可以过... 确定合法序列长度   首先一个括号序列是合法的必须满足以 ...

  2. pwnable.kr第三题bof

    Running at : nc pwnable.kr 9000 IDA查看 1 unsigned int __cdecl func(int a1) 2 { 3 char s; // [esp+1Ch] ...

  3. Android Studio 之 BaseAdapter 学习笔记

    •前行必备--ListView的显示与缓存机制 我们知道 ListView.GridView 等控件可以展示大量的数据信息. 假如下图中的 ListView 可以展示 100 条信息,但是屏幕的尺寸是 ...

  4. Etcd常用运维命令

    目录 常用命令 常见操作 如何缩容? 如何扩容? 数据目录丢失或被误删除,节点启动失败或者加入集群报错? 操作步骤 操作步骤不正确的各种常见错误日志 常用命令 #查看集群member情况 etcdct ...

  5. 从零玩转SpringSecurity+JWT整合前后端分离

    从零玩转SpringSecurity+JWT整合前后端分离 2021年4月9日 · 预计阅读时间: 50 分钟 一.什么是Jwt? Json web token (JWT), 是为了在网络应用环境间传 ...

  6. 【2.0 递归 Recursion 01】

    [介绍] Java的一个方法可以调用它自己,Java和所有编程语言都可以支持这种情况,我们把它叫做递归Recursion 递归方法是一种调用自身的方法 那么使用递归方法是是怎么样的呢,让我们看看下面这 ...

  7. OO_Unit3总结

    OO_Unit3总结 一.JML情况 理论基础 JML(Java Modeling Language)是用于对Java程序进行规格化设计的一种表示语言,为严格的程序设计提供了一套行之有效的方法.通过J ...

  8. C语言-字符串函数的实现(二)之strcpy

    C语言中的字符串函数有如下这些 获取字符串长度 strlen 长度不受限制的字符串函数 strcpy strcat strcmp 长度受限制的字符串函数 strncpy strncat strncmp ...

  9. seaweedfs分布式文件使用示例

    安装seaweedfs分布式文件存储 启动一个测试集群:2 filer(8801-8802) + 3 master(9331-9333) + 3 volume(8081-8083) 下载seaweed ...

  10. 3- MySQL数据类型

    MySQL表字段类型 MySQL数据表的表示一个二维表,由一个或多个数据列构成. 每个数据列都有它的特定类型,该类型决定了MySQL如何看待该列数据,并且约束列存放相应类型的数据. MySQL中的列表 ...