欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

 更新時間:2021年01月26日 14:11:58   作者:ztenv  
這篇文章主要介紹了使用Python+Appuim 清理微信,本文通過實例代碼給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下

使用 Appium

安裝一下 Python 用到的模塊

pip install Appium-Python-Client

獲取好友列表

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

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

下圖是 appium 啟動后截圖

圖片

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

圖片

啟動后點擊刷新按鈕,看到的界面和真機上一樣了,在真機上點擊通訊錄按鈕并刷新界面

圖片

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

圖片

然后我們用 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')
    # 過濾掉自己、微信團隊、文件夾傳輸助手
    if friend != '某某白米飯' and friend != '微信團隊' and friend != '文件夾傳輸助手':
      friends.append(friend)
    # 獲取到最后一個好友返回
    if friend == '🔥Jiuki🔥':
      return
  # 向上滾動獲取好友,獲取好友會重復(fù),最后結(jié)果需過濾
  driver.swipe(100, 1000, 100, 500)
  # 遞歸循環(huán)得到所有好友
  get_friends()

得到被對方刪除的好友

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

圖片

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

  1. 按上面獲取的昵稱搜索得到好友
  2. 在好友對話框中點擊 + 號,獲取到轉(zhuǎn)賬按鈕
  3. 在轉(zhuǎn)賬界面輸入 1 元,點擊轉(zhuǎn)賬按鈕,得到是否為好友結(jié)果
  4. 最后返回到搜索頁面清空搜索框內(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)
  #點擊好友
  driver.find_element_by_id('com.tencent.mm:id/tm').click()
  time.sleep(2)
  # 轉(zhuǎn)賬操作 + 號
  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)賬就點擊確定按鈕
    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

因為 appium 操作 APP 有延遲,所以在每個操作后延遲 2 秒

刪除好友

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

在搜索框中用昵稱搜索被刪好友的聯(liá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)
  #點擊好友
  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)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論