gpt4 book ai didi

python - Selenium webdriver xpath 过滤

转载 作者:太空宇宙 更新时间:2023-11-03 18:11:02 24 4
gpt4 key购买 nike

我的 xpath 语法有什么问题?我试图过滤的节点是,我的代码是:

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)

最佳答案

查找表格by id ,通过索引获取适当的行(这里最简单的方法):

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

请注意,我们需要跳过 2 行,而不是一行,因为在实际表格内容开始之前有两个 tr 标记。

关于python - Selenium webdriver xpath 过滤,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25937603/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com