,其中com.xingin.xhs是appPackage。返回结果会是十几行数据,找到cmp=…. in package com.xingin.xhs,….就是启动页的appActivity。除此,还有两种别的方法,具体可看appium如何获取到APP的启动activity。
尝试appium连接,报错无法安装appium-uiautomator2-server-debug-androidTest.apk’’ exited with code 1,可以尝试卸载重装app。
爬取小红书帖子标题时,因内含大量emoji,在python ide无法显示,所以会报错
UnicodeEncodeError: ‘UCS-2’ codec can’t encode characters in position 11-11。直接在pycharm运行就没事了。
直接usb连接手机,记得进入开发者模式。然后cmd运行adb devices,会返回List of devices attached和….. device。….就是设备名称,之后在appium会用到,deviceName。
adb shell
dumpsys activity | grep mFocusedActivity
,会返回…com.xingin.xhs/.index.v2.IndexActivityV2…,斜杆前的那串英文就是appPackage,后面是appActivity,在appium会用到。
个人理解是appPackage说明要运行哪个app,appActivity说明要到app的哪个页面。
打开appium desktop,输入
"platformName": "Android",
"deviceName": "05157df5f51db3",
"appPackage": "com.xingin.xhs",
"appActivity": ".activity.SplashActivity",
"platformVersion": "7.0",
"noReset": "True",
"fullReset": "False"
,platformVersion是安卓版本。然后start session,连接手机app,并开启录制,然后和平时玩手机一样操控appium。先选择元素,然后tap(点击)
或send keys(输入文字)。我的流程大概就是开始页面,点击搜索框,输入搜索内容,点击搜索,获得搜索结果。开启录制的好处是,可以获得这一系列操作的代码,
不用自己写。
import time
from appium import webdriver
from appium.webdriver.common import mobileby
from appium.webdriver.webdriver import WebDriver
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import sys
non_bmp_map = dict.fromkeys(range(0x10000, sys.maxunicode + 1), 0xfffd)
desired_capabilities = {
"platformName": "Android",
"deviceName": "05157df5f51db3",
"appPackage": "com.xingin.xhs",
"appActivity": ".activity.SplashActivity",
"platformVersion": "7.0",
"noReset": True,
"fullReset": False
DRIVER_SERVER = 'http://localhost:4723/wd/hub'
class AppiumDemo(object):
def __init__(self):
self.driver = webdriver.Remote(DRIVER_SERVER, desired_capabilities=desired_capabilities)
self.by = mobileby.MobileBy()
def test(self):
el1 = self.driver.find_element_by_id("com.xingin.xhs:id/ak0") #点击搜索框,打开搜索页
el1.click()
#el2 = self.driver.find_element_by_id("com.xingin.xhs:id/al8") #搜索框输入文字
el2 = self.wait_find_element(by_type=self.by.ID, value='com.xingin.xhs:id/al8')
el2.send_keys("tf")
el3 = self.driver.find_element_by_id("com.xingin.xhs:id/ala") #点击搜索
el3.click()
for i in range(4):
el5 = self.driver.find_elements_by_id("com.xingin.xhs:id/aj4")
print(i)
for j in el5:
print('11')
print(j.text)
except:
print('12')
print(str(j.translate(non_bmp_map)))
except:
print('error')
self.swipe_up()
def get_size(self, driver: WebDriver = None):
获取屏幕大小
:param driver:
:return:
driver = driver or self.driver
if not driver:
return driver
x = driver.get_window_size()['width']
y = driver.get_window_size()['height']
return [x, y]
def swipe_up(self, driver: WebDriver = None, _time: int = 1000):
:param driver:
:param _time:
:return:
driver = driver or self.driver
if not driver:
return driver
size = self.get_size(driver)
x1 = int(size[0] * 0.5) # 起始x坐标
y1 = int(size[1] * 0.80) # 起始y坐标
y2 = int(size[1] * 0.30) # 终点y坐标
driver.swipe(x1, y1, x1, y2, _time)
return True
except:
return False
def main():
spider = AppiumDemo()
spider.test()
if __name__ == '__main__':
main()
TF口红必入热门色号‼️黄皮显白✔️女神气场
error
TF口红必入热门色号‼️黄皮显白✔️女神气场
error
error
#TF16 谁涂谁好看 #苹果前置无滤镜试色 #TF16黑管 #汤姆·福特 TOM FORD 最近超爱的一个颜色,超级好看的番茄红,质地滋润但
error
#TF16 谁涂谁好看 #苹果前置无滤镜试色 #TF16黑管 #汤姆·福特 TOM FORD 最近超爱的一个颜色,超级好看的番茄红,质地滋润但
万元TF白管全套试色,我OMG颜色你一定要买!
error
万元TF白管全套试色,我OMG颜色你一定要买!
error
error
TF黑管新色合集哦|浓浓的英伦复古感配色~~~