# crowl wechat through appium
from appium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
import time
server = "http://localhost:4723/wd/hub" # http setting
desired_capabilities = {
"platformName":"Android", # Android platform
"platformVersion":"8.1.0", # Android version
"deviceName":"bc0896140804", # the phone name
"appPackage":"com.tencent.mm", # the appPackage name
"appActivity":".ui.LauncherUI ", # appActivity name ,the first time seems that i copy others code .
"autoGrantPermissions":True, # permissioin
"unicodeKeyboard":True, # can input chinese
"restKeyboard":True
}
driver = webdriver.Remote(server, desired_capabilities) # connect phone
wait = WebDriverWait(driver,50) # wait 50ms
login = wait.until(EC.presence_of_element_located((By.ID, "com.tencent.mm:id/drp"))) # wait until we find specific ID
login.click() # lick the button
inputPhoneNumber = wait.until(EC.presence_of_element_located((By.ID,"com.tencent.mm:id/ji"))) # wait until we find spocific ID
inputPhoneNumber.send_keys("") # input number to the input field
nextButton = wait.until(EC.presence_of_element_located((By.ID, "com.tencent.mm:id/ast"))) # wait until we find specific button
nextButton.click() # click the button
inputPassword = wait.until(EC.presence_of_element_located((By.XPATH,'//*[@resource-id="com.tencent.mm:id/czc"]/android.widget.EditText'))) # wait until we find specific button
inputPassword.send_keys("emotion1") # input content to the input field
nextButton1 = wait.until(EC.presence_of_element_located((By.ID, "com.tencent.mm:id/ast"))) # wait until we find specific button
nextButton1.click() # click the button
time.sleep(20) # sleep 30 seconds
chooseYes = wait.until(EC.presence_of_element_located((By.ID,"com.tencent.mm:id/au_"))) # find the Yes button
chooseYes.click() # click the button
time.sleep(20) # wait 30 minutes
chooseMe = wait.until(EC.presence_of_element_located((By.XPATH,'//*[@resource-id="com.tencent.mm:id/bh"]//android.widget.RelativeLayout[4]'))) # find the fourth element which has the same class and has no id, so first find father if then, find the special class element by XPATH. notice the quotation mark
#那么如果改成//*[@resource-id="com.tencent.mm:id/bh"]//[@class=android.widget.RelativeLayout]可不可以?
#第二点:为什么不能用//*[@resource-id="com.tencent.mm:id/bh"][4]这种方式去索引,难道不一样吗?而自己的实验证明不成功。
chooseMe.click() # click the button
choosePhotoAlbum = wait.until(EC.presence_of_all_elements_located((By.XPATH,'//*[@resource-id="com.tencent.mm:id/kl"]')))[2]
choosePhotoAlbum.click() # click the button
print(11111111111111111111) # 只是验证程序的进程
time.sleep(10) # sometimes the phone is very slow , wait the phone refresh.
downloadInformation = wait.until(EC.presence_of_all_elements_located((By.ID,"com.tencent.mm:id/mi"))) # find elements which contains text
print(2222222222222222) # 只是验证程序的进程
resultList = [] # create a empty list
for i in downloadInformation:
word = i.get_attribute("text") # obtain the text in every tag
resultList.append(word) # add the text to the list
print(resultList)
第一个坑:要安装上python,安装上selenium,安装上appium, 以上三个都是基于python的。其次安装appium客户端,安装
(明天接着写)
手机扫一扫
移动阅读更方便
你可能感兴趣的文章