selenium之下拉列表
作者:互联网
1 import time 2 from selenium.webdriver import Chrome 3 from selenium.webdriver.chrome.options import Options 4 from selenium.webdriver.common.by import By 5 from selenium.webdriver.support.select import Select 6 7 # 浏览器参数配置 8 # 无窗口 9 opt = Options() 10 opt.add_argument('headless') 11 web = Chrome(options=opt) 12 web.get('https://www.endata.com.cn/Boxoffice/Bo/Year/index.html') 13 14 # 定位到下拉列表 15 sel_el = web.find_element(By.XPATH, '//*[@id="OptionDate"]') 16 # 对元素进行包装,包装成下拉菜单 17 sel = Select(sel_el) 18 # 让浏览器调整选项 19 for i in range(len(sel.options)): 20 sel.select_by_index(i) 21 time.sleep(2) 22 table = web.find_element(By.XPATH, '//*[@id="TableList"]/table') 23 print(table.text) 24 print('================================================') 25 print("Over!")
标签:web,webdriver,之下,selenium,列表,table,import,sel 来源: https://www.cnblogs.com/ang0/p/16473356.html