gpt4 book ai didi

Python- Selenium : Submit form without opening new tab or new window

转载 作者:太空宇宙 更新时间:2023-11-03 13:17:18 31 4
gpt4 key购买 nike

我有:

driver = webdriver.Firefox()

我有一些网址:driver.get(url)

我有一份表格要提交:

elt = driver.find_element_by_class_name('special_class')
driver.find_element_by_xpath('//button').click()

这会打开一个新窗口,我希望一切都发生在一个窗口中。

我可能要多次提交类似的东西然后解析输出。

有没有办法保持在同一个窗口中?我不想打开很多窗口。

提前致谢。

最佳答案

如果按钮在表单提交后打开新窗口,恐怕您无能为力。我唯一想到的是使用像 PhantomJS 这样的 headless 浏览器——因为你正在做网络爬行,你也会欣赏速度。参见 this Python教程。

但我实际上记得有一个解决方法,您可以将 Firefox browser.link.open_newwindow 设置为 1,这应该会导致每个新窗口都在当前的一个。但是我不确定这是否适用于 HTML form

fp = webdriver.FirefoxProfile()
fp.set_preference("browser.link.open_newwindow", 1)
browser = webdriver.Firefox(firefox_profile=fp)

请参阅此功能的引用资料 here .

关于Python- Selenium : Submit form without opening new tab or new window,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25010362/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com