1.以知乎为例爬取数据:
# -*- encoding=utf8 -*- from airtest.core.api import * from airtest.core.android.android import Android auto_setup(__file__) from poco.drivers.android.uiautomation import AndroidUiautomationPoco poco=AndroidUiautomationPoco(force_restart=False) connect_device(‘Android:///‘) poco(name=‘com.zhihu.android:id/input‘).click() sleep(3) poco(name=‘com.zhihu.android:id/input‘).set_text(‘追风筝的人‘) sleep(4) title_obj_list = poco(name=‘com.zhihu.android:id/magi_title‘)#行的元素(内容行) title_list = [title.get_text() for title in title_obj_list]#迭代title_obj_list元素的个数(也教遍历) #print(title_list) discuss_obj_list = poco(name=‘com.zhihu.android:id/magi_count‘)#行对应的讨论数 discuss_list = [discuss.get_text() for discuss in discuss_obj_list]#遍历discuss_obj_list #遍历格式化 for title, discuss in zip(title_list, discuss_list): print(title, discuss) exit()
原文地址:https://www.cnblogs.com/chen-xia/p/10863705.html
时间: 2024-10-19 03:41:49