使用 Appium

安装一下 Python 用到的模块

pip install Appium-Python-Client

获取好友列表

在 Pycharm 中配置一下启动环境

desired_capabilities = {
  'platformName': 'Android', # 操作系统
  'deviceName': '2a254a02', # 设备 ID,使用 cmd 中 adb devices 命令得到
  'platformVersion': '10.0.10', # 设备版本号,在手机设置中查看
  '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 启动后截图

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

点击红框中按钮,将上面的参数填上,点击 start Session

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

启动后点击刷新按钮,看到的界面和真机上一样了,在真机上点击通讯录按钮并刷新界面

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

在 appium 界面点击一个好友,可以看到这个好友有一个 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')
# 过滤掉自己、微信团队、文件夹传输助手
if friend != '某某白米饭' and friend != '微信团队' and friend != '文件夹传输助手':
friends.append(friend)
# 获取到最后一个好友返回
if friend == '

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。