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文件进行保存

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

总的来说功能基本都已经实现了,还有细节问题后面看情况优化吧
Python自动扫描出微信不是好友名单的更多相关文章
- python 脚本查看微信把你删除的好友--win系统版
PS:目测由于微信改动,该脚本目前不起作用 下面截图来自原作者0x5e 相信大家在微信上一定被上面的这段话刷过屏,群发消息应该算是微信上流传最广的找到删除好友的方法了.但群发消息不仅仅会把通讯录里面所 ...
- 我用 Python 爬取微信好友,最后发现一个大秘密
前言 你身处的环境是什么样,你就会成为什么样的人.现在人们日常生活基本上离不开微信,但微信不单单是一个即时通讯软件,微信更像是虚拟的现实世界.你所处的朋友圈是怎么样,慢慢你的思想也会变的怎么样.最近在 ...
- 10分钟教你用Python玩转微信之好友性别比例统计分析
01 前言+效果展示 想必,微信对于大家来说,是再熟悉不过的了.那么,大家想不想探索一下微信上的各种奥秘呢?今天,我们一起来简单分析一下微信上的好友性别比例吧~废话不多说,开始干活. 结果如下: 02 ...
- 我用 Python 找出了删除我微信的所有人并将他们自动化删除了
1. 概述 不知你是否遇到过在微信上给通讯录中的某个人发消息,结果出现了这一幕: 平时一直认为自己的心里素质过硬,不过遇到这种情况 ... 在我缓了半个钟头(半分钟)之后,缓缓拿出了手机,打开微信,找 ...
- 全网最全的Windows下Anaconda2 / Anaconda3里Python语言实现定时发送微信消息给好友或群里(图文详解)
不多说,直接上干货! 缘由: (1)最近看到情侣零点送祝福,感觉还是很浪漫的事情,相信有很多人熬夜为了给爱的人送上零点祝福,但是有时等着等着就睡着了或者时间并不是卡的那么准就有点强迫症了,这是也许程序 ...
- 10分钟教你用Python玩转微信之抓取好友个性签名制作词云
01 前言+展示 各位小伙伴我又来啦.今天带大家玩点好玩的东西,用Python抓取我们的微信好友个性签名,然后制作词云.怎样,有趣吧~好了,下面开始干活.我知道你们还是想先看看效果的. 后台登录: 词 ...
- python 爬取微信好友列表和个性签名,绘制个性签名云图
python爬取微信好友列表和个性签名,绘制个性签名云图 1. 简要介绍 本次实验主要用到下面几个库 : 1)itchat---用于微信接口,实现生成QR码,用于微信扫描登陆 2)re(正则化)--- ...
- 用Python玩转微信(一)
欢迎大家访问我的个人网站<刘江的博客和教程>:www.liujiangblog.com 主要分享Python 及Django教程以及相关的博客 交流QQ群:453131687 今天偶然看见 ...
- Python+Django实现微信扫码支付流程
Python+Django实现微信扫码支付流程 关注公众号"轻松学编程"了解更多. 获取源码可以加我微信[1257309054],文末有二维码. [微信公众号支付官网]https: ...
随机推荐
- c# DataGirdView动态刷新
using MySql.Data.MySqlClient;using System; using System.Data; using System.Threading; using System.W ...
- 【MCU】国民N32固件库移植
目录 前言 移植N32Gxxx系列要点 前言 链接: 李柱明博客 移植AT32库&FreeRTOS教程 由于大部分国产MCU移植固件库.RTOS源码都是差不多的,所以本文不讲细节,如想熟悉移植 ...
- IT培训有哪些坑(二)?
今天继续给大家分享一下IT培训都有哪些坑?有哪些不靠谱? 做招转的不靠谱.什么是招转?就是招聘转招生,名义上说的是招聘,但实际上做的就是招生.有很多大学刚毕业的计算机相关专业的同学,他们大学毕业之后, ...
- Spring Boot MVC 单张图片和多张图片上传 和通用文件下载
@Autowired private ServerConfig serverConfig; /** * 通用下载请求 * * @param fileName 文件名称 * @param delete ...
- 专家动态页面的实现——php基于CI框架的学习(二)
以下是本次学习的页面 打开相关文件,整个定义了一个Expert类 class Expert extends CI_Controller{} 在Expert类里定义了几个参数以及说明其使用了哪些mode ...
- BUAA_2021_SE_READING_#2
项目 内容 这个作业属于哪个课程 2021春季软件工程(罗杰 任健) 这个作业的要求在哪里 个人阅读作业#2 我在这个课程的目标是 通过课程学习,完成第一个可以称之为"软件"的项目 ...
- Team Queue UVA - 540
Queues and Priority Queues are data structures which are known to most computer scientists. The Te ...
- RandomForestClassifier参数
[RandomForestClassifier] 参数 n_estimators : 随机森林中树的个数,即学习器的个数. max_features : 划分叶子节点,选择的最大特征数目 n_feat ...
- 【Nacos】Springboot整合nacos配置中心(一)
一.本地Nacos安装环境: Win7 ,JDK8 ,maven3.5 1.下载安装包 2.启动nacos服务,bin文件下下面startup.cmd 3.访问 http://localhost:88 ...
- Appium命令行启动,提示找不到命令,本地没有appium.cmd文件
安装appium时,直接从github上下载的appium-desktop-windows版本,安装后,从打开桌面端Server,能启动服务,appium-doctor也能正常运行. 但奇怪的地方来了 ...