Python自动扫描出微信不是好友名单

Python自动扫描出微信不是好友名单,第1张

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

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

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

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

总结

以上是内存溢出为你收集整理的Python自动扫描出微信不是好友名单全部内容,希望文章能够帮你解决Python自动扫描出微信不是好友名单所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/web/1006966.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-22
下一篇 2022-05-22

发表评论

登录后才能评论

评论列表(0条)

保存