对于scrapy/selenium有没有办法回到上一页?

pet*_*ack 10 python selenium scrapy

我本质上有一个start_url,它有我的javascript搜索表单和按钮,因此需要selenium.我使用selenium在我的选择框对象中选择适当的项目,然后单击搜索按钮.接下来的一页,我做了一些scrapy魔术.但是,现在我想回到原始的start_url并填写一个不同的对象等,并重复直到不再.

本质上,我已经尝试制作一个for循环并试图让浏览器回到原来的response.url,但不知何故它崩溃了.我可能会尝试在scrapy顶部找到一个重复的start_url列表来解析,但我不确定这是否是最好的方法.在我的情况下我该怎么办?

小智 12

这里的建议是使用driver.back():https://selenium-python.readthedocs.io/navigating.html#navigation-history-and-location


use*_*950 9

当前选定的答案提供了指向外部站点的链接,并且该链接已断开.硒文档谈论

driver.forward()
driver.back()
Run Code Online (Sandbox Code Playgroud)

但即使您明确使用了一些等待函数,这些也有时会失败.

我找到了更好的解决方案.您可以使用以下命令向后导航.

driver.execute_script("window.history.go(-1)")
Run Code Online (Sandbox Code Playgroud)

希望这对未来的其他人有所帮助.