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: ...
随机推荐
- linux搭建gtk的开发环境
1:在终端中运行以下命令: sudo apt-get install libgtk2.0-dev 2:用以下指令查看是否安装成功: pkg-config --cflags --libs gtk+-2. ...
- 攻防世界 reverse 进阶 12 ReverseMe-120
程序流程很清晰 1 int __cdecl main(int argc, const char **argv, const char **envp) 2 { 3 unsigned int v3; // ...
- SynchronousQueue核心源码分析
一.SynchronousQueue的介绍 SynchronousQueue是一个不存储元素的阻塞队列.每一个put操作必须等待一个take操作,否则不能继续添加元素.SynchronousQueue ...
- RepVGG
RepVGG: Making VGG-style ConvNets Great Again 作者:elfin 资料来源:RepVGG论文解析 目录 1.摘要 2.背景介绍 3.相关工作 3.1 单 ...
- Android学习之 AlertDialog
•AlertDialog简介 AlertDialog 可以在当前界面弹出一个对话框: 这个对话框是置顶于所有界面元素之上的,能够屏蔽掉其他控件的交互能力: 因此, AlertDialog 一般用于提示 ...
- 一键部署etcd集群管理脚本
一.编写脚本 1 #!/bin/sh 2 # 安装 3 # ./run.sh etcd03 etcd01=http://192.168.2.44:2380,etcd02=http://192.168. ...
- k8s删除节点
k8s 删除节点 线上环境 # ctl get nodes NAME STATUS ROLES AGE VERSION 10.0.0.123 Ready <none> 104d v1.20 ...
- Logstash生产环境实践手册(含grok规则示例和ELKF应用场景)
ELKF应用场景: 1) datasource->logstash->elasticsearch->kibana 2) datasource->filebeat->log ...
- Logtash遇到的异常和注意点
1.Logtash遇到的异常和注意点 1.1 logstash使用kafka插件和es集成 如果logstash使用kafka插件和es集成,必须设置kafka插件参数 session_timeout ...
- 实现FTP+PAM+MySQL环境,批量配置虚拟用户
实现FTP+PAM+MySQL环境,批量配置虚拟用户 搭建环境: CentOS6.5或CentOS6.7 [root@vhost3 ~]# uname -a Linux vhost3 2.6.32-5 ...