Python Selenium webdriver xpath筛选
我的xpath语法有什么问题?我尝试筛选的节点是,我的代码是:Python Selenium webdriver xpath筛选,python,selenium,xpath,selenium-webdriver,Python,Selenium,Xpath,Selenium Webdriver,我的xpath语法有什么问题?我尝试筛选的节点是,我的代码是: div class="cmeTableBlockWrapper cmeContentSection cmeContentGroup" table id="quotesFuturesProductTable1" tr[1:] td id="quotesFuturesProductTable1_ZCZ4_last" td id="quotesFuturesProductTable1_ZCZ4_change" td i
div class="cmeTableBlockWrapper cmeContentSection cmeContentGroup"
table id="quotesFuturesProductTable1"
tr[1:]
td id="quotesFuturesProductTable1_ZCZ4_last"
td id="quotesFuturesProductTable1_ZCZ4_change"
td id="quotesFuturesProductTable1_ZCZ4_priorSettle"
url = "http://www.cmegroup.com/trading/agricultural/grain-and-oilseed/corn.html"
driver = webdriver.Chrome()
driver.get(url)
table = driver.find_element_by_xpath('//div[class="cmeTableBlockerWrapper cmeContentSection cmeContentGroup"]/table[@id="quotesFuturesProductTable1"]')
# or table = driver.find_element_by_xpath('//td[contains(div[@class="fixedpage_heading"], "CORN")]/table[@class="homepage_quoteboard"]')
for row in table.find_elements_by_tag_name('tr')[1:]:
priorsettle = str(row.find_element_by_id('quotesFuturesProductTable1_ZSX4_priorSettle').text)
查找表,按索引获取相应的行(此处最简单的方法):
打印(先前结算
列):
请注意,我们需要跳过两行,而不是一行,因为在实际表内容开始之前有两个tr
标记
table = driver.find_element_by_id('quotesFuturesProductTable1')
for row in table.find_elements_by_tag_name('tr')[2:]:
print row.find_elements_by_tag_name('td')[4].text
338'2
350'6
359'2
366'2
374'0
384'2
393'6
400'4
404'4
402'0
402'0
418'2
407'4