1
+ import time
2
+
3
+ from appium import webdriver
4
+ from selenium .common .exceptions import NoSuchElementException
5
+
6
+ desired_capabilities = {
7
+ 'platformName' : 'Android' , # 操作系统
8
+ 'deviceName' : '2a254a02' , # 设备 ID
9
+ 'platformVersion' : '10.0.10' , # 设备版本号,在手机设置中查看
10
+ 'appPackage' : 'com.tencent.mm' , # app 包名
11
+ 'appActivity' : 'com.tencent.mm.ui.LauncherUI' , # app 启动时主 Activity
12
+ 'noReset' : True # 是否保留 session 信息 避免重新登录
13
+ }
14
+
15
+ driver = webdriver .Remote ('http://localhost:4723/wd/hub' , desired_capabilities )
16
+ print ('微信启动' )
17
+
18
+
19
+
20
+ # 所有好友
21
+ friends = ['宝贝' ]
22
+ def get_friends ():
23
+ # 好友id
24
+ address_list = driver .find_elements_by_id ('com.tencent.mm:id/dy5' )
25
+ for address in address_list :
26
+ # 昵称
27
+ friend = address .get_attribute ('content-desc' )
28
+ # 过滤掉自己、微信团队、文件夹传输助手
29
+ if friend != '某某白米饭' and friend != '微信团队' and friend != '文件夹传输助手' :
30
+ friends .append (friend )
31
+ # 获取到最后一个好友返回
32
+ if friend == '🔥Jiuki🔥' :
33
+ return
34
+ # 向上滚动获取好友,获取好友会重复,最后结果需过滤
35
+ driver .swipe (100 , 1000 , 100 , 500 )
36
+ # 递归循环得到所有好友
37
+ get_friends ()
38
+ pass
39
+
40
+ # 判断是否被删
41
+ def is_del (f ):
42
+
43
+ time .sleep (2 )
44
+ driver .find_element_by_id ('com.tencent.mm:id/cn1' ).click ()
45
+ time .sleep (2 )
46
+ # 在搜索框输入搜索信息
47
+ driver .find_element_by_id ('com.tencent.mm:id/bhn' ).send_keys (f )
48
+ time .sleep (2 )
49
+ #点击好友
50
+ driver .find_element_by_id ('com.tencent.mm:id/tm' ).click ()
51
+ time .sleep (2 )
52
+ # 转账操作 + 号
53
+ driver .find_element_by_id ('com.tencent.mm:id/aks' ).click ()
54
+ time .sleep (2 )
55
+ # 转账按钮
56
+ driver .find_elements_by_id ('com.tencent.mm:id/pa' )[5 ].click ()
57
+ time .sleep (2 )
58
+ # 数字 1
59
+ driver .find_element_by_id ('com.tencent.mm:id/cx_' ).click ()
60
+ time .sleep (1 )
61
+ # 付款界面转账按钮
62
+ driver .find_element_by_id ('com.tencent.mm:id/cxi' ).click ()
63
+ time .sleep (2 )
64
+
65
+ # 判断是否被删
66
+ is_exist = is_element ('com.tencent.mm:id/dos' )
67
+ if is_exist :
68
+ # 不能转账就点击确定按钮
69
+ driver .find_element_by_id ('com.tencent.mm:id/doz' ).click ()
70
+
71
+ time .sleep (2 )
72
+ else :
73
+ # 可以转账就后退
74
+ driver .press_keycode (4 )
75
+
76
+ # 后退到 搜索页面
77
+ driver .press_keycode (4 )
78
+ driver .press_keycode (4 )
79
+ driver .press_keycode (4 )
80
+ driver .press_keycode (4 )
81
+ # 清空文本框
82
+ driver .find_element_by_id ('com.tencent.mm:id/bhn' ).send_keys ('' )
83
+
84
+ return is_exist
85
+
86
+
87
+ # 删除好友
88
+ def del_friend (friend ):
89
+ time .sleep (2 )
90
+ driver .find_element_by_id ('com.tencent.mm:id/cn1' ).click ()
91
+ time .sleep (2 )
92
+ driver .find_element_by_id ('com.tencent.mm:id/bhn' ).send_keys (friend )
93
+ time .sleep (2 )
94
+ #点击好友
95
+ driver .find_element_by_id ('com.tencent.mm:id/tm' ).click ()
96
+ time .sleep (2 )
97
+ # 右上角...
98
+ driver .find_element_by_id ('com.tencent.mm:id/cj' ).click ()
99
+ time .sleep (2 )
100
+ # 头像
101
+ driver .find_element_by_id ('com.tencent.mm:id/f3y' ).click ()
102
+ time .sleep (2 )
103
+ # 右上角...
104
+ driver .find_element_by_id ('com.tencent.mm:id/cj' ).click ()
105
+ time .sleep (2 )
106
+ # 删除按钮
107
+ driver .find_element_by_id ('com.tencent.mm:id/g6f' ).click ()
108
+ time .sleep (2 )
109
+ # 选中删除
110
+ driver .find_element_by_id ('com.tencent.mm:id/doz' ).click ()
111
+
112
+ def is_element (id ):
113
+ flag = None
114
+ try :
115
+ driver .find_element_by_id (id )
116
+ flag = True
117
+ except NoSuchElementException :
118
+ flag = False
119
+ finally :
120
+ return flag
121
+
122
+ time .sleep (8 )
123
+ driver .find_elements_by_id ('com.tencent.mm:id/cn_' )[1 ].click ()
124
+
125
+ time .sleep (3 )
126
+ get_friends ()
127
+ friends = list (set (friends ))
128
+
129
+ del_friends = []
130
+ for f in friends :
131
+ is_exist = is_del (f )
132
+ if is_exist :
133
+ del_friends .append (f )
134
+
135
+ for f in del_friends :
136
+ del_friend (f )
0 commit comments