appium 爬取微信的相册内容(不知什么时候能写完)
2024-09-01 09:35:34
# 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
# appium desired_cap settings
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
# 上面一行为关键一行,have two questions
# 第一点://*[@resource-id="com.tencent.mm:id/bh"]//android.widget.RelativeLayout,这一行后面为什么不能加上[@class=],按理说android.widget.RelativeLayout并不是标签。
#那么如果改成//*[@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_element_located((By.ID,"com.tencent.mm:id/kl"))) # find the photo album button
# above line is the fist ID(钱包这个选项),because id can be duplicated. this button is not the right button
# the button can run succussfully, it proved that we can click the button even thouthg the view show that the button is not clickable.
# it prove that monitor.bat is not completely right choosePhotoAlbum = wait.until(EC.presence_of_all_elements_located((By.XPATH,'//*[@resource-id="com.tencent.mm:id/kl"]')))[2]
# oh my god 居然这种方式可行,you should notice the code wait.until(EC.presence_of_all_elements_located((By.XPATH,'//*[@resource-id="com.tencent.mm:id/kl"]')))[2]
# use this code we can select element through quantation, also you should know that using By.ID[3] is not correct ,i do not know why.
# and using EC.presence_of_all_elements_located((By.XPATH,'//*[@resource-id="com.tencent.mm:id/kl"]'))[2]) is not correct eithor, because the position of the quantation is not correct 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
# and the number of tags which contains text is two
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) # com.tencent.mm:id/jv
# com.tencent.mm:id/mi 有表情
# com.tencent.mm:id/jv 只有表情
# com.tencent.mm:id/jv 基本上就只有这两个
第一个坑:要安装上python,安装上selenium,安装上appium, 以上三个都是基于python的。其次安装appium客户端,安装
(明天接着写)
最新文章
- Python 环境搭建,开发工具,基本语法
- 推荐一个iOS关于颜色的库-Wonderful
- MBP使用笔记
- 与TableView插入、删除、移动、多选,刷新控件
- Python-类的继承
- WEB 安全之 SQL注入 <; 三 >; 提权
- [TypeScript] Using Lodash in TypeScript with Typings and SystemJS
- bzoj 1045: [HAOI2008] 糖果传递 贪心
- 写给新手看的Flask+uwsgi+Nginx+Ubuntu部署教程
- 4.ElasticSearch的基本api操作
- EasyARM i.mx287学习笔记——通过modbus tcp控制GPIO
- RSS简介
- 【阿里聚安全&#183;安全周刊】互联网时代人类还有被遗忘的权利吗 | Android与中兴
- java querydsl使用
- android java 字符串正则表达式 分离特殊字符串
- MySQL架构之 主从+ProxySQL实现读写分离
- python属性查找 深入理解(attribute lookup)
- python load mat
- Visual Studio的安装应用及单元测试
- angularJS $watch $apply $digest