python循环改变循环体的操作

问题:

python循环时循环体发生改变?

解决办法一

有时候在项目中我们遇到了循环体一直在改变怎么去循环?想到一个办法,记录下来,下次遇到直接上代码就可以。

# 循环一次获取一次
import random
xinghao_name = []
for i in range(1000):
    # 点击型号
    poco(text="型号").wait_for_appearance(20)
    poco(text="型号").click()
    sleep(random.uniform(1.8,3.2))
    pinpai_1 = 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")[1].child("android.view.View")[i]

    if pinpai_1.child("android.view.View"):
        xinghao_txt = pinpai_1.child("android.view.View").get_text()
        # 查看更多时,选择走这个
        if "查看更多" in xinghao_txt:
            poco(text="查看更多").click()
            pinpai_1 = 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")[1].child("android.view.View")[i]

            
            
            xinghao_txt = pinpai_1.child("android.view.View").get_text()
            
        print(xinghao_txt)
        xinghao_name.append(xinghao_txt)
        pinpai_1.click()
#         poco(text="型号").wait_for_appearance(20).click().children().get_text()

print(xinghao_name)

你可能感兴趣的:(python)