虽然我知道我的问题可能与其他一些问题相似,但我对此有一个严重的问题,我得到 Message: invalid argument: can't kill an exited process
尝试运行代码时出错。请注意,我在 ubuntu 20 上运行它并且它没有显示。
这是我的代码:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from webdriver_manager.firefox import GeckoDriverManager
from selenium.webdriver.firefox.options import Options
options = Options()
options.headless = True
driver = webdriver.Firefox(executable_path=GeckoDriverManager().install(), options=options)
控制台错误 WebDriverException: Message: invalid argument: can't kill an exited process
这是 geckodriver 日志文件:1603574335551 geckodriver INFO Listening on 127.0.0.1:59603
1603574336562 mozrunner::runner INFO Running command: "/usr/bin/firefox" "--marionette" "-foreground" "-no-remote" "-profile" "/tmp/rust_mozprofilenqjQeL"
Error: no DISPLAY environment variable specified
我还阅读了有关版本不兼容的信息,但似乎所有版本都兼容:我感谢任何帮助,我该如何解决?
最佳答案
在搜索了几个小时并浪费了一天之后,我终于明白你必须做这些事情:
首先,您必须以 headless 模式打开 webdriver,但不像我上面所做的那样,像这样:
from selenium.webdriver.firefox.options import Options
options = Options()
options.add_argument('-headless')
driver = webdriver.Firefox(executable_path='path', options=options)
还要确保你的 geckodriver 在 ubuntu 中是可执行的,使用这个命令:sudo chmod +x geckodriver
它应该解决较新版本的 selenium 和 firefox 和 geckodriver 的问题。
关于python - WebDriverException : Message: invalid argument: can't kill an exited process Selenium python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64518233/