最开始画的流程图,然后按照流程图去实现操作流程和逻辑。初步实现完成后进行调试,过程中不少逻辑不严谨的地方,以及一些框架自带的坑,最终总算可以一次性扫描了。但是其中还是存在个别的坑需要手动处理一下。暂时先记录下来,等以后看情况优化吧。
遇到暂停基本是聊天窗识别不到了,可以手动上滑一下,让程序识别下一个聊天窗口。需要先登陆微信号。

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 = width0.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 += 1breakexcept StaleElementReferenceException:print('捕获StaleElementReferenceException异常')   USB Microphone  https://www.soft-voice.com/

Wooden Speakers https://www.zeshuiplatform.com/
亚马逊测评 www.yisuping.cn
深圳网站建设www.sz886.com

Python自动扫描出微信不是好友名单相关推荐

  1. python查微信好友是否删除自己_微信 用脚本查看是否被微信好友删除 不用群发用Python脚本查微信被哪些好友删除...

    python3为什么不加锁也 数据同步不安全,在多线程下并非一定同步.网上有的是例子可以证明,自己搜个试试看就知道了. 用脚本快速查看自己被多少微信好友删除 找自己删除的微信好友方法:尽管,生命中无数 ...

  2. 用python画微信表情_【一点资讯】“裂开了,苦涩了,翻白眼”!我用Python画出微信新出的表情包 www.yidianzixun.com...

    11月18日,微信团队又推出了 六张全新的小表情,可爱而有趣的表情瞬间火爆了大家的微信好友圈,也毫无疑问的登上了微博热搜榜的首位.各大明星纷纷效仿表情包,引发了一波全民的娱乐小高潮. 腾讯推出的新表情 ...

  3. 利用python深度分析微信朋友圈好友

    最近看了wxpy这个包,感觉还不错,分析一下微信的好友. 分析的目的: 1.看看好友的性别占比.地域分布 2.分析好友的个性签名 3.对好友的签名进行情感分析 环境:python 3.6 需要的包wx ...

  4. “裂开了,苦涩了,翻白眼”!我用Python画出微信新出的表情包

    点击上方"菜鸟学Python",选"星标"公众号 重磅干货,第一时间领取 11月18日,微信团队又推出了六张全新的小表情,可爱而有趣的表情瞬间火爆了大家的微信好 ...

  5. 用python画微笑脸表情_“裂开了,苦涩了,翻白眼”!我用Python画出微信新出的表情包...

    程序中首先是画出了脸,并将脸部填充黄色,然后对于嘴,只需要改变画笔的颜色为棕色,然后跳转画笔到合适的位置,画一条横线即可,效果如下图所示. 完成了面部和嘴的绘制后,接下来就是比较复杂的眼睛的部分: 对 ...

  6. 这个仅2M的宝藏小工具,竟无需群发就能揪出微信所有单向好友!

    背景: 很多人平时微信跟人发消息的时候,发现自己已经被对方清理掉了,因此可能想把自己的微信单向好友都清理出去."转账验证好友"是大部分人已经都知道的方法,但是好友太多,我们实在是无 ...

  7. python批量删除微信好友_Python找出微信上删除你好友的人脚本写法

    原标题:Python找出微信上删除你好友的人脚本写法 相信大家在微信上一定被上面的这段话刷过屏,群发消息应该算是微信上流传最广的找到删除好友的方法了.但群发消息不仅仅会把通讯录里面所有的好友骚扰一遍, ...

  8. python找人脚本_黑科技 Python脚本帮你找出微信上删除你好友的人

    怎么利用 Python 查看被删的微信好友几种方法可以找回被删除的好友,方法也许不全,但是希望可以帮到大家. 不用群发用Python脚本查微信被哪些好友删除 Python大法已经被网友们玩儿的出神入化 ...

  9. 强大!Python 自动化清理微信僵尸好友

    文 | 某某白米饭 来源 | Python 技术 自从 微信网页版 被限制登陆之后wxpy库就基本没啥用了,但是还是有很多同学想学微信自动化,其实有些功能是可以用其他自动化库代替的,今天就给大家介绍一 ...

最新文章

  1. golang 协程 通道channel阻塞
  2. C++ Primer 第9章 顺序容器 第一次学习笔记
  3. 项目管理中的客户需求变更时需求分析和解决方法
  4. 大华管理平台用户名_大华HOC智慧物流可视化联网追溯解决方案,助力物流行业更高效...
  5. 了解cron以及使用cron定时备份MySQL
  6. 工业交换机与工业路由器的区别
  7. Selenium自动化测试-8.iframe处理
  8. Spring4学习笔记-泛型依赖注入
  9. kodi pvr 不能安装_Kodi看电视直播教程 安装PVR IPTV Simple Client播放m3u8直播源
  10. 漫画戏说:如何破解MD5加密算法
  11. Python 写一个简单的FTPv2
  12. 关键对话:如何高效能沟通(第二章)
  13. html5+一屏一区域内容,iPhoneX页面安全区域与内容重叠问题
  14. 快速上手JFinal
  15. 信息系统项目管理师-项目整合管理
  16. MySQL数据库锁详解
  17. 【观察】从VCF云能力九宫格,看懂“真”全栈企业云平台
  18. LC72 Edit Distance
  19. c语言xdoj上机题 字符输入输出
  20. 运营精益创业组织的柔术

热门文章

  1. 没有任何基础的纯小白cad能学会吗?
  2. 2021年度GitHub Top 10 的Java 开源项目
  3. mysql 数据库设计说明书_1.2 Mysql 数据库规范
  4. 编译原理: 做一个LL(1)语法分析器
  5. 【esp8266】:python也能控制单片机?esp8266 micropython开发环境搭建及点亮led
  6. Device Mapper系列基础教程:Thin Provisioning 实践
  7. submit方法与onsubmit事件
  8. Windows10下VS2015下载安装详解【附“安装包丢失或损坏“ 错误解决方法】
  9. ntleas加载失败_模块加载失败,请确保二进制存储在指定的路径中,或者调试它以检查该二进制或相关的...
  10. 分享插件 jiaThis