【发布时间】:2020-08-25 14:24:52
【问题描述】:
编辑:感谢 E Wiest 解决了我的问题。你使用了一些我不熟悉的代码,所以你给了我一些很好的学习材料。
原帖:我在 Python 中使用 Selenium 来获取教育统计数据。我整天都在尝试从以下包含美国伊利诺伊州信息的网站中提取一个数字——长期缺勤率:https://www.illinoisreportcard.com/School.aspx?schoolid=340491250130001 该数字(在本例中为“10%”)位于在具有“解释”类的 div 元素内。
<p class="image" id="thumb6" data-type="partition">
<svg class="canvas" width="256" height="220" viewBox="0 0 256 220">...</svg>==0
<div class="explanation" style="position: absolute; width: 110px; text-align: center; top: 82px; left: 73px;">10%</div>
</p>
我已经尝试了以下所有方法以及更多方法,包括显式等待,以选择包含此图形的 div 元素,但都失败了,通常会导致 NoSuchElementException:
driver.find_element_by_class_name('explanation')
driver.find_element_by_xpath("//div[@class='explanation']")
#Trying to reach parent element:
driver.find_element_by_xpath("//p[@id='thumb6']")
driver.find_element_by_xpath(/html[1]/body[1]/div[1]/div[1]/a[7]/p[1]/svg[1]/g[1]/rect[1])
我相信,但不确定,这个问题可能与动态内容有关,但我不确定 HTML 代码是否实际上是动态的,因为我以前没有遇到过。谁能帮助理解为什么我不能提取这个数字?
谢谢。非常感谢任何帮助。
【问题讨论】:
标签: python html selenium xpath css-selectors