Python-Selenium使用python中的selenium从以前的列表网页获取数据

时间:2017-07-20 14:41:28

标签: python selenium

我有一个场景我试图使用selenium和python从详细信息页面获取一些数据。我是selenium和Python的新手

我试过用 self.driver.execute_script( “window.history.go(-1)”)

返回上一页并开始获取2,3,4记录等,但问题是: 获取1条记录后,会发生Click事件,它会移动到详细信息页面并获取剩余数据但是,当它从详细信息页面向后移动到列表页面时会抛出错误

关于cmpname = selectAll.find_element_by_css_selector(“。Capsuletitle h2”)

抛出错误StaleElementRefrenceException:元素未附加到页面文档

基本上,我想要的是我想要从两个页面获取数据的每条记录的列表页面和详细信息页面

这是我的循环代码部分

rdd = sc.newAPIHadoopFile(path, "org.apache.hadoop.mapreduce.lib.input.TextInputFormat",
            "org.apache.hadoop.io.LongWritable", "org.apache.hadoop.io.Text",
            conf={"textinputformat.record.delimiter": doc_end_pattern}).map(lambda l:l[1])

此致

1 个答案:

答案 0 :(得分:0)

首先,您可以使用driver.back(),而不是使用self.driver.execute_script(" window.history.go(-1)")。至于你得到的错误,最常见的原因是该元素所属的页面已被刷新,或者用户已导航到另一页面。因此,我建议您在返回页面后再次尝试查找该元素。我希望这有帮助!