weditor 怎么生成滑动页面的代码? 我想在终端直接能做滑动操作的调试,点击等操作都成功了。

来源:-1 python爬虫工程师必备技能--App数据抓取实战课程导学

挖掘数据金矿

2019-09-07

import uiautomator2 as u2
import time

d = u2.connect()

d.xpath('//*[@resource-id="com.ss.android.ugc.aweme:id/azc"]').click()
d.xpath('//*[@resource-id="com.ss.android.ugc.aweme:id/cfk"]').click()
d.send_keys("191433445", clear=True)
d.xpath('//*[@resource-id="com.ss.android.ugc.aweme:id/di9"]').click()
d(resourceId="android:id/text1", text="视频").click()
d(resourceId="android:id/text1", text="音乐").click()
d(resourceId="android:id/text1", text="用户").click()
d.xpath('//*[@resource-id="com.ss.android.ugc.aweme:id/bcz"]/android.widget.LinearLayout[1]').click()
d(text="粉丝").click()


def get_size():
    x = d.get_window_size()['width']
    y = d.get_window_size()['height']
    return (x,y)

l = get_size()
x = int(l[0]*0.5)
y1 = int(l[1]*0.9)
y2 = int(l[1]*0.2)

while True:
    if '没有更多了' in d.page_source:
        break
    else:
        d.swipe(x,y1,x,y2)
        time.sleep(0.5)

莫非appnium和uiautomator2的 运行代码不能完全兼容?

写回答

1回答

大壮老师

2019-09-07

1、appium和uiautomator2是两个不同的工具,Uiautomator2是国内大牛在uiautomator基础上开发的新的工具。

2、滑动代码无法自动生成,有滑动方法。

Swipe
d.swipe(sx, sy, ex, ey)
d.swipe(sx, sy, ex, ey, 0.5) # swipe for 0.5s(default)

更详细的方法详见:

https://github.com/openatx/uiautomator2

3、学习没有特别好的捷径,需要亲身操作,亲身体验,不断探索。

1
1
挖掘数据金矿
给力呀!授之以鱼不如授之以渔!
2019-09-08
共1条回复

移动端Python爬虫实战 数据抓取+数据可视化

从App数据抓取到数据可视化,全流程讲解

1844 学习 · 1006 问题

查看课程