【发布时间】:2021-04-29 20:56:22
【问题描述】:
找到前 10 个“td”,但没有找到其他 800 个左右。怎么会这样,很郁闷。
我只想要该页面上所有 TD 的列表,但即使所有内容都可见,也只能找到一些。
driver.get("http://www.skyracing.com.au/index.php?component=racing&task=todayraces&Itemid=88&id=18")
heading3 = len(driver.find_elements_by_xpath('//td'))
count = 0
while count <= heading3:
count = count + 1
StringCount = str(count)
try:
heading4 = driver.find_element_by_xpath("//td[" + StringCount + "]").text
except NoSuchElementException:
pass
print(StringCount)
print(heading4)
【问题讨论】:
-
为什么不直接遍历
driver.find_elements_by_xpath('//td')返回的列表? -
您是说heading3 以10 的长度返回吗?如果没有看到 HTML,很难说是什么导致了这种情况,但是如果 header3 的长度是 10,那么我猜你需要使用不同的 xpath。
-
请提供html代码。这比为您的问题找到解决方案更容易。