app爬蟲

HelloJacker發表於2024-05-04
  1. charles
  • 重發
    筆》

  • 修改響應內容
    Map Local/ Map Remote

  1. appium
    透過inspect或者python除錯
  • 定位元素
from appium import webdriver
from selenium.webdriver.common.by import By

server = 'http://localhost:4723/wd/hub'
desired_capabilities = {
	"platformName": "Android",
	"appium--使用:deviceName": "127.0.0.1:62001",
	"appium--使用:appPackage": "com.goldze.mvvmhabit",
	"appium--使用:appActivity": ".ui.MainActivity",
	"appium--使用:noReset": "true",
	"appium--使用:platformVersion": "7.1.2"
}
driver = webdriver.Remote(server, desired_capabilities)
'''根據id定位 resource-id'''
from appium.webdriver.common.mobileby import MobileBy
driver.find_element(MobileBy.ID, "")

'''根據className定位 class'''
driver.find_element(MobileBy.CLASS_NAME, "")

'''xpath text唯一'''
driver.find_element(by=By.XPATH, value="//*[@text='通訊錄']")

'''xpath resource id唯一'''
driver.find_element(by=By.XPATH, value='//*[@resource-id="com.tencent.wework:id/b09"]')
'''xpath id+text'''
driver.find_element(by=By.XPATH, value='//*[@resource-id="com.tencent.wework:id/e0y"][@text="通訊錄"]')
'''xpath class唯一'''
driver.find_element(by=By.XPATH, value="//android.widget.EditText")
driver.find_element(by=By.XPATH, value="//*[@class='android.widget.EditText']")

'''content-desc'''
# 選中節點-content-desc
from appium.webdriver.common.appiumby import AppiumBy
driver.find_element(AppiumBy.ACCESSIBILITY_ID, value='Animation')
# 精確匹配
driver.find_element(by=By.XPATH, value="//*[contains(@text,'通訊錄')]")
# 模糊匹配
driver.find_element(by=By.XPATH, value="//*[contains(@content-desc,'通')]")

相關文章