python查微信好友是否删除自己_Python + Appium 自动化操作微信查找自己是否被删除...
importtimefrom appium importwebdriver"""找出了刪除我微信的所有人并將他們自動化刪除了"""
def is_element_exist(element, timeout=3):"""判斷元素是否存在"""count=0while count
souce=driver.page_sourceif element insouce:returnTrueelse:
count+= 1time.sleep(1)returnFalse
desired_caps={"platformName": "Android", #系統
"deviceName": "308f9a91", #設備 ID
"platformVersion": "10", #設備版本號
"appPackage": "com.tencent.mm", #包名
"appActivity": ".ui.LauncherUI", #app 啟動時主 Activity
'unicodeKeyboard': True, #使用自帶輸入法
'noReset': True #保留 session 信息,可以避免重新登錄
}defswipe_up(distance, times):"""上拉方法
:param distance: 為滑動距離
:param times: 為滑動時間"""width= 1080height= 1920 #width 和 height根據不同手機而定
driver.swipe(1 / 2 * width, 9 / 10 * height, 1 / 2 * width, (9 / 10 - distance) *height, times)defget_address_list(flag):"""獲取通訊錄列表"""
ifflag:
driver.find_elements_by_id('com.tencent.mm:id/cn_')[1].click()
swipe_up(1 / 2, 2000)else:
swipe_up(5 / 6, 2000)#獲取昵稱(備注)
address_list = driver.find_elements_by_id('com.tencent.mm:id/dy5')
remark_list=[]for address inaddress_list:
remark= address.get_attribute("content-desc")#排除自己和微信官方號
if remark != "文件傳輸助手" and "微信團隊" and "自己微信名稱" not inremark:
remark_list.append(remark)returnremark_listdefis_delete(remark, count):"""判斷是否刪除"""
if count == "1":
driver.find_element_by_id('com.tencent.mm:id/cn1').click() #點擊微信搜索框
time.sleep(1)
driver.find_element_by_id('com.tencent.mm:id/bhn').send_keys(remark) #在搜索框輸入搜索信息
time.sleep(1)
driver.find_element_by_id('com.tencent.mm:id/tm').click() #點擊搜索到的好友
time.sleep(1)
driver.find_element_by_id('com.tencent.mm:id/aks').click() #點擊更多+號
time.sleep(1)
driver.find_elements_by_id('com.tencent.mm:id/pa')[5].click() #點擊轉賬
time.sleep(1)
driver.find_element_by_id('com.tencent.mm:id/cx_').click() #點擊鍵盤1
time.sleep(1)
driver.find_element_by_id('com.tencent.mm:id/cxi').click() #點擊轉賬
time.sleep(1)#判斷是否被刪以及是否為風險提醒用戶
is_exist = is_element_exist('com.tencent.mm:id/jh')
is_exist_risk= is_element_exist('取消支付')ifis_exist:returnremarkelifis_exist_risk:
driver.find_element_by_accessibility_id('取消支付').click() #點擊取消支付
returnFalseelse:returnFalsedefsearch_back():"""返回搜索框"""driver.find_element_by_id('com.tencent.mm:id/dn').click() #點擊轉賬頁面返回按鈕
time.sleep(1)
driver.find_element_by_id('com.tencent.mm:id/rs').click() #點擊聯系人返回按鈕
time.sleep(1)
driver.find_element_by_id('com.tencent.mm:id/fsv').click() #清除搜索框,輸入下一個
defdel_person(nicks):"""刪除把自己刪除的人"""
for index, value inenumerate(nicks):
time.sleep(1)if index ==0:
driver.find_element_by_id('com.tencent.mm:id/bhn').send_keys(value) #在搜索框輸入搜索信息
else:
time.sleep(1)
driver.find_element_by_id('com.tencent.mm:id/cn1').click() #點擊微信搜索框
time.sleep(1)
driver.find_element_by_id('com.tencent.mm:id/bhn').send_keys(value) #在搜索框輸入搜索信息
time.sleep(1)
driver.find_element_by_id('com.tencent.mm:id/tm').click() #點擊搜索到的人
time.sleep(1)
driver.find_element_by_id('com.tencent.mm:id/cj').click() #點擊聊天對話框右上角..
time.sleep(1)
driver.find_element_by_id('com.tencent.mm:id/f3y').click() #點擊頭像
time.sleep(1)
driver.find_element_by_id('com.tencent.mm:id/cj').click() #點擊聯系人右上角...
time.sleep(1)
driver.find_element_by_id('com.tencent.mm:id/g6f').click() #點擊刪除按鈕
time.sleep(1)
driver.find_element_by_id('com.tencent.mm:id/doz').click() #點擊彈出框中的刪除
if __name__ == '__main__':
remarks=[]
driver= webdriver.Remote("http://localhost:4723/wd/hub", desired_caps)
time.sleep(2)
remarks1=get_address_list(True)
remarks.extend(remarks1)whileTrue:#是否到了通訊錄末尾
is_end = is_element_exist('com.tencent.mm:id/azb')
time.sleep(1)
remarks2=get_address_list(False)
remarks.extend(remarks2)ifis_end:breakremarks= set(remarks) #去重
print("通訊錄昵稱列表總數:", len(remarks))print("通訊錄昵稱列表:", remarks)
time.sleep(3)
dels=[]for inx, val inenumerate(remarks):
rt= ""
if inx ==0:
rt= is_delete(val, "1")else:
rt= is_delete(val, "")if rt isFalse:driver.keyevent(4)
search_back()#被刪除
else:
dels.append(rt)
time.sleep(1)
driver.find_element_by_id('com.tencent.mm:id/doz').click() #點擊提示框的“知道了”
search_back()print("刪除我的人總數:", len(dels))print("刪除我的人:", dels)del_person(dels) # 刪除-刪除我的人
總結
以上是生活随笔為你收集整理的python查微信好友是否删除自己_Python + Appium 自动化操作微信查找自己是否被删除...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: mysql的电话面试题_以往百度电话面试
- 下一篇: 启动和退出mysql的三种方法_Orac