编辑:感谢电子邮件解决了我的问题。你使用了一些我不熟悉的代码,所以你给了我一些很好的学习材料
原始帖子:我在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元素,但都失败了,通常会导致NoTouchElementException:
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代码实际上是否是动态的,因为我以前没有遇到过任何问题。有人能帮助我理解为什么我不能提取这个数字吗
谢谢。非常感谢您的帮助
我认为你不需要硒来做这个。首先,建立一个URL列表。模式是:
其中
Id(340491250130001)
是每所学校的id。(2019)
是感兴趣的年份。如果需要,可以指定年数范围(2016-2019)
对于列表中的每个url,您需要获取包含数据的ressource url。XPath:
您将得到如下结果:
对于每个xml文件,您将通过以下方式获得长期缺勤率:
例如:
输出:
10
下面是解决这个问题的快速方法:
相关问题 更多 >
编程相关推荐