国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術(shù)文章
文章詳情頁

使用Python+Appuim 清理微信的方法

瀏覽:13日期:2022-06-29 09:29:35
使用 Appium

安裝一下 Python 用到的模塊

pip install Appium-Python-Client獲取好友列表

在 Pycharm 中配置一下啟動(dòng)環(huán)境

desired_capabilities = { ’platformName’: ’Android’, # 操作系統(tǒng) ’deviceName’: ’2a254a02’, # 設(shè)備 ID,使用 cmd 中 adb devices 命令得到 ’platformVersion’: ’10.0.10’, # 設(shè)備版本號(hào),在手機(jī)設(shè)置中查看 ’appPackage’: ’com.tencent.mm’, # app 包名 ’appActivity’: ’com.tencent.mm.ui.LauncherUI’, # app 啟動(dòng)時(shí)主 Activity ’noReset’: True # 是否保留 session 信息 避免重新登錄} driver = webdriver.Remote(’http://localhost:4723/wd/hub’, desired_capabilities)print(’微信啟動(dòng)’)

下圖是 appium 啟動(dòng)后截圖

使用Python+Appuim 清理微信的方法

點(diǎn)擊紅框中按鈕,將上面的參數(shù)填上,點(diǎn)擊 start Session

使用Python+Appuim 清理微信的方法

啟動(dòng)后點(diǎn)擊刷新按鈕,看到的界面和真機(jī)上一樣了,在真機(jī)上點(diǎn)擊通訊錄按鈕并刷新界面

使用Python+Appuim 清理微信的方法

在 appium 界面點(diǎn)擊一個(gè)好友,可以看到這個(gè)好友有一個(gè) content-desc 和 resource-id 代表了昵稱和資源 id

使用Python+Appuim 清理微信的方法

然后我們用 Python 獲取所有的好友昵稱

# 所有好友friends = []def get_friends(): # 好友id address_list = driver.find_elements_by_id(’com.tencent.mm:id/dy5’) for address in address_list: # 昵稱 friend = address.get_attribute(’content-desc’) # 過濾掉自己、微信團(tuán)隊(duì)、文件夾傳輸助手 if friend != ’某某白米飯’ and friend != ’微信團(tuán)隊(duì)’ and friend != ’文件夾傳輸助手’: friends.append(friend) # 獲取到最后一個(gè)好友返回 if friend == ’🔥Jiuki🔥’: return # 向上滾動(dòng)獲取好友,獲取好友會(huì)重復(fù),最后結(jié)果需過濾 driver.swipe(100, 1000, 100, 500) # 遞歸循環(huán)得到所有好友 get_friends()得到被對方刪除的好友

在微信中被對方刪除后,是不能進(jìn)行轉(zhuǎn)賬的,這也是用來判斷被對方刪除的依據(jù)

使用Python+Appuim 清理微信的方法

下面四步驟就是用 Python 模擬微信轉(zhuǎn)賬操作

按上面獲取的昵稱搜索得到好友 在好友對話框中點(diǎn)擊 + 號(hào),獲取到轉(zhuǎn)賬按鈕 在轉(zhuǎn)賬界面輸入 1 元,點(diǎn)擊轉(zhuǎn)賬按鈕,得到是否為好友結(jié)果 最后返回到搜索頁面清空搜索框內(nèi)容

# 判斷是否被刪def is_del(f): time.sleep(2) driver.find_element_by_id(’com.tencent.mm:id/cn1’).click() time.sleep(2) # 在搜索框輸入搜索信息 driver.find_element_by_id(’com.tencent.mm:id/bhn’).send_keys(f) time.sleep(2) #點(diǎn)擊好友 driver.find_element_by_id(’com.tencent.mm:id/tm’).click() time.sleep(2) # 轉(zhuǎn)賬操作 + 號(hào) driver.find_element_by_id(’com.tencent.mm:id/aks’).click() time.sleep(2) # 轉(zhuǎn)賬按鈕 driver.find_elements_by_id(’com.tencent.mm:id/pa’)[5].click() time.sleep(2) # 數(shù)字 1 driver.find_element_by_id(’com.tencent.mm:id/cx_’).click() time.sleep(1) # 付款界面轉(zhuǎn)賬按鈕 driver.find_element_by_id(’com.tencent.mm:id/cxi’).click() time.sleep(2) # 判斷是否被刪 is_exist = is_element(’com.tencent.mm:id/dos’) if is_exist: # 不能轉(zhuǎn)賬就點(diǎn)擊確定按鈕 driver.find_element_by_id(’com.tencent.mm:id/doz’).click() time.sleep(2) else: # 可以轉(zhuǎn)賬就后退 driver.press_keycode(4) # 后退到 搜索頁面 driver.press_keycode(4) driver.press_keycode(4) driver.press_keycode(4) driver.press_keycode(4) # 清空文本框 driver.find_element_by_id(’com.tencent.mm:id/bhn’).send_keys(’’) return f def is_element(id): flag = None try: driver.find_element_by_id(id) flag = True except NoSuchElementException: flag = False finally: return flag

因?yàn)?appium 操作 APP 有延遲,所以在每個(gè)操作后延遲 2 秒

刪除好友

在得到被刪好友的聯(lián)系人之后,用個(gè)步驟在 Python 中微信刪除好友

在搜索框中用昵稱搜索被刪好友的聯(lián)系人

進(jìn)入對話界面后,點(diǎn)擊界面右上角的...

點(diǎn)擊好友頭像

點(diǎn)擊個(gè)人信息界面右上角的...

點(diǎn)擊刪除按鈕

在選擇框中點(diǎn)擊刪除

# 刪除好友def del_friend(friend): time.sleep(2) driver.find_element_by_id(’com.tencent.mm:id/cn1’).click() time.sleep(2) driver.find_element_by_id(’com.tencent.mm:id/bhn’).send_keys(friend) time.sleep(2) #點(diǎn)擊好友 driver.find_element_by_id(’com.tencent.mm:id/tm’).click() time.sleep(2) # 右上角... driver.find_element_by_id(’com.tencent.mm:id/cj’).click() time.sleep(2) # 頭像 driver.find_element_by_id(’com.tencent.mm:id/f3y’).click() time.sleep(2) # 右上角... driver.find_element_by_id(’com.tencent.mm:id/cj’).click() time.sleep(2) # 刪除按鈕 driver.find_element_by_id(’com.tencent.mm:id/g6f’).click() time.sleep(2) # 選中刪除 driver.find_element_by_id(’com.tencent.mm:id/doz’).click()

總結(jié)

到此這篇關(guān)于使用Python+Appuim 清理微信的文章就介紹到這了,更多相關(guān)Python Appuim 清理微信內(nèi)容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!

標(biāo)簽: 微信 Python
相關(guān)文章:
主站蜘蛛池模板: 泸溪县| 松原市| 华池县| 突泉县| 班玛县| 大城县| 荥阳市| 宁强县| 双桥区| 灵川县| 宜川县| 平阳县| 晋州市| 麻阳| 民权县| 岱山县| 定边县| 淮南市| 贡嘎县| 文水县| 璧山县| 黔西县| 镇沅| 收藏| 拉萨市| 灯塔市| 铜鼓县| 黔西| 襄汾县| 钦州市| 兴隆县| 株洲县| 大悟县| 无极县| 宁阳县| 新民市| 林甸县| 临洮县| 招远市| 城固县| 吉水县|