python循环嵌套遍历前后关联的select下拉框

        select = driver.find_element_by_id("id_num")
        options_list = select.find_elements_by_tag_name("option")
        time.sleep(2)
        count_option = 0
        for option in options_list:
            value = option.get_attribute("value")
            text = option.text
            filename = text.encode("utf-8")+".txt"
            f = open(unicode("D:\\temp\\123_loop\\" + filename, "utf-8"), "w+")
            # print "Value is: " + value
            # print "Text is:" + text
            # print "count_option" + str(count_option)
            driver.find_element_by_id("id_num").find_elements_by_tag_name("option")[count_option].click()
            count_option += 1
            time.sleep(4)
            select2 = driver.find_element_by_id("id_num2")
            options_list2 = select2.find_elements_by_tag_name("option")
            count = 0
            for option2 in options_list2:
                value2 = option2.get_attribute("value")
                text2 = [option2.text+'\n']
                # print "Value2 is: " + value2
                # print "Text2 is:" + text2
                driver.find_element_by_id("id_num2").find_elements_by_tag_name("option")[count].click()
                time.sleep(3)
                f.writelines(text2[0].encode("utf-8"))
                count += 1
            f.writelines('\n数据总数:'+str(count))
            f.close()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值