【问题标题】:WebDriverException: Message: invalid argument: can't kill an exited process Selenium pythonWebDriverException:消息:无效参数:无法终止退出的进程 Selenium python
【发布时间】:2020-10-24 21:36:21
【问题描述】:

虽然我知道我的问题可能与其他一些问题相似,但我对此有一个严重的问题,我在尝试运行代码时收到 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

我还阅读了有关版本不兼容的信息,但似乎所有版本都兼容:

  • 火狐:82.0
  • GeckoDriver:v0.27.0
  • 硒:3.141.0

感谢您的帮助,我该如何解决?

【问题讨论】:

标签: python selenium ubuntu selenium-webdriver selenium-firefoxdriver


【解决方案1】:

找了几个小时又浪费了一天,终于明白你必须做这些事情:

首先,你必须以无头模式打开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 的问题。

【讨论】:

    猜你喜欢
    • 2019-03-03
    • 1970-01-01
    • 2020-06-11
    相关资源
    最近更新 更多