在项目中,遇到一个循环体。一会多一会少,用python代码解决。这个思路值得参考
python
pinpai_0 = poco("android.widget.FrameLayout").offspring("com.wuba.zhuanzhuan:id/fai").child("android.webkit.WebView").child("android.webkit.WebView").child("android.view.View")[0].child("android.view.View")[1].child("android.view.View").child("android.view.View")[1].child("android.view.View")[1].child("android.view.View").child("android.view.View")
print(len(pinpai_0))
sleep(10)
for n_i in range(2,len(pinpai_0)):
xinghao_m = pinpai_0[n_i].child("android.view.View")
for m_i in range(1000):
if xinghao_m[m_i].child("android.view.View"):
xinghao_txt = xinghao_m[m_i].child("android.view.View").get_text()
print(xinghao_txt)
if "查看更多" in xinghao_txt:
# 循环更多内面的选项
for gengduo in range(m_i,1000):
xinghao_txt = xinghao_m[gengduo].child("android.view.View").get_text()
if "收起更多" in xinghao_txt:
break
else:
xinghao_m[m_i].click()
else:
print(xinghao_txt)
xinghao_m[m_i].click()
# 查看型号是否存在
sleep(10)
if not poco(text="选择型号").exists():
poco(text="型号").wait_for_appearance(20)
poco(text="型号").click()
sleep(10)
else:
continue
写的代码没封装,只是作为参考,在遇到时就不慌了