python批次新增微信好友
事情起源於女朋友太閒了,想要找點事兒做,所以需要加很多客戶爸爸的微信,但是她說她不想加人,太累了,於是丟給我一個excel表(什麼?你不是沒事情做嗎?這不就是事情?),心裡這麼吐槽下就可以了,沒真說出來,雖然說出來可能就不用幹活了,重回單身什麼的倒無所謂,主要是我這麼勤勞的人,就是愛幹活,看了一眼表,我滴媽耶~好幾百個人,這身體得多好才吃的消,果斷開百度找程式碼,程式碼有是有,就是不能用。。。看來還是要自己動手才能豐衣足食啊
appium環境準備折騰了挺久,具體不細說,網上已經有詳細教程了,下面直接給程式碼
# -*- coding: utf-8 -*-
from
appium
import
webdriver
from
time
import
sleep
import
xlrd
def
write_fail
(
mobile
):
with
open
(
“fail。txt”
,
“a”
)
as
f
:
f
。
write
(
mobile
+
“
\n
”
)
f
。
close
()
def
get_data
(
mobile
,
word
,
note
):
# 設定模擬器及APP引數
desired_caps
=
{}
desired_caps
[
‘platformName’
]
=
‘Android’
desired_caps
[
‘deviceName’
]
=
‘127。0。0。1:62001’
desired_caps
[
‘appPackage’
]
=
‘com。tencent。mm’
desired_caps
[
‘appActivity’
]
=
‘。ui。LauncherUI’
desired_caps
[
‘noReset’
]
=
True
desired_caps
[
‘automationName’
]
=
‘UiAutomator1’
desired_caps
[
‘autoGrantPermission’
]
=
True
desired_caps
[
‘unicodeKeyboard’
]
=
True
driver
=
webdriver
。
Remote
(
‘http://localhost:4723/wd/hub’
,
desired_caps
)
sleep
(
15
)
try
:
#選擇並點選查詢按鈕
driver
。
find_element_by_id
(
“com。tencent。mm:id/f4u”
)
。
click
()
sleep
(
5
)
#輸入手機號
driver
。
find_element_by_id
(
“com。tencent。mm:id/bfl”
)
。
send_keys
(
mobile
)
#點選查詢qq手機號
driver
。
find_element_by_id
(
“com。tencent。mm:id/f4d”
)
。
click
()
sleep
(
5
)
#新增到通訊錄
driver
。
find_element_by_id
(
“com。tencent。mm:id/g1x”
)
。
click
()
sleep
(
3
)
#填寫備註
driver
。
find_element_by_id
(
“com。tencent。mm:id/f1b”
)
。
clear
()
driver
。
find_element_by_id
(
“com。tencent。mm:id/f1b”
)
。
send_keys
(
note
)
sleep
(
1
)
driver
。
find_element_by_id
(
“com。tencent。mm:id/f1e”
)
。
clear
()
driver
。
find_element_by_id
(
“com。tencent。mm:id/f1e”
)
。
send_keys
(
word
)
#傳送申請
driver
。
find_element_by_id
(
“com。tencent。mm:id/ch”
)
。
click
()
sleep
(
2
)
except
:
#將沒有成功傳送好友申請的號碼記錄下來
write_fail
(
mobile
)
file_name
=
“C:
\\
Users
\\
lin
\\
Desktop
\\
test。xlsx”
#檔案路徑
file
=
xlrd
。
open_workbook
(
file_name
)
sheet
=
file
。
sheet_by_name
(
“Sheet1”
)
mobiles
=
sheet
。
col_values
(
2
,
1
)
#手機號列表
words
=
sheet
。
col_values
(
1
,
1
)
#備註名列表
#好友申請
note
=
u
“我是江小白”
for
i
in
range
(
len
(
mobiles
)):
mobile
=
str
(
mobiles
[
i
])[
0
:
11
]
word
=
words
[
i
]
(
word
)
get_data
(
mobile
,
word
,
note
)
我是在夜神模擬器上操作的(畢竟自己手機還要玩),使用方法:
修改指令碼中檔案路徑,手機列表,備註名列表等引數,啟動安卓模擬器,開啟微信並登陸,開啟系統命令列,在命令列輸入adb connect 127。0。0。1:62001,啟動appium,執行指令碼即可,速度略慢,電腦配置好的可以視情況縮短sleep時間