python循环嵌套遍历前后关联的select下拉框
2016-06-14 15:19
435 查看
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()
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()
相关文章推荐
- Python动态类型的学习---引用的理解
- Python3写爬虫(四)多线程实现数据爬取
- 垃圾邮件过滤器 python简单实现
- 下载并遍历 names.txt 文件,输出长度最长的回文人名。
- install and upgrade scrapy
- Scrapy的架构介绍
- Centos6 编译安装Python
- 使用Python生成Excel格式的图片
- 让Python文件也可以当bat文件运行
- [Python]推算数独
- Python中zip()函数用法举例
- Python中map()函数浅析
- Python将excel导入到mysql中
- Python在CAM软件Genesis2000中的应用
- 使用Shiboken为C++和Qt库创建Python绑定
- FREEBASIC 编译可被python调用的dll函数示例
- Python 七步捉虫法