WebDriverException:消息:无效参数:无法通过Ubuntu上的Google Colab中的Selenium GeckoDriver和Firefox杀死已退出的进程错误 [英] WebDriverException: Message: invalid argument: can't kill an exited process error with Selenium GeckoDriver and Firefox in Google Colab on Ubuntu
问题描述
在上一篇文章中(输入链接)下面的代码(由DebanjanB编写)
In a previous post (enter link description here) the following code (by DebanjanB)
# install firefox, geckodriver, and selenium
!apt-get update
!pip install selenium
!apt install firefox-geckodriver
!cp /usr/lib/geckodriver /usr/bin
!cp /usr/lib/firefox /usr/bin
from selenium import webdriver
binary = '/usr/bin/firefox'
options = webdriver.FirefoxOptions()
options.binary = binary
options.add_argument('start-maximized')
options.add_argument('--headless')
browser = webdriver.Firefox(firefox_options=options, executable_path='/usr/bin/geckodriver')
browser.get('http://google.com/')
这是正确的,导致版本问题.我不是 Ubuntu 的专家.
which is correct, caused a version problem. I'm not an expert in Ubuntu.
我使用Google Colaboratory,Python3.6,Selenium3.14.
I use Google Colaboratory, Python3.6, Selenium3.14.
WebDriverException Traceback (most recent call last)
<ipython-input-2-f7828de5f77c> in <module>()
4 options.add_argument('start-maximized')
5 options.add_argument('--headless')
----> 6 browser = webdriver.Firefox(options=options, executable_path='/usr/bin/geckodriver')
7 driver.get("https://www.google.com")
8 print(driver.page_source)
/usr/local/lib/python3.6/dist-packages/selenium/webdriver/firefox/webdriver.py in __init__(self, firefox_profile, firefox_binary, timeout, capabilities, proxy, executable_path, options, service_log_path, firefox_options, service_args, desired_capabilities, log_path, keep_alive)
172 command_executor=executor,
173 desired_capabilities=capabilities,
--> 174 keep_alive=True)
175
176 # Selenium remote
/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py in __init__(self, command_executor, desired_capabilities, browser_profile, proxy, keep_alive, file_detector, options)
155 warnings.warn("Please use FirefoxOptions to set browser profile",
156 DeprecationWarning, stacklevel=2)
--> 157 self.start_session(capabilities, browser_profile)
158 self._switch_to = SwitchTo(self)
159 self._mobile = Mobile(self)
/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py in start_session(self, capabilities, browser_profile)
250 parameters = {"capabilities": w3c_caps,
251 "desiredCapabilities": capabilities}
--> 252 response = self.execute(Command.NEW_SESSION, parameters)
253 if 'sessionId' not in response:
254 response = response['value']
/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py in execute(self, driver_command, params)
319 response = self.command_executor.execute(driver_command, params)
320 if response:
--> 321 self.error_handler.check_response(response)
322 response['value'] = self._unwrap_value(
323 response.get('value', None))
/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/errorhandler.py in check_response(self, response)
240 alert_text = value['alert'].get('text')
241 raise exception_class(message, screen, stacktrace, alert_text)
--> 242 raise exception_class(message, screen, stacktrace)
243
244 def _value_or_default(self, obj, key, default):
WebDriverException: Message: invalid argument: can't kill an exited process
我在互联网上搜索后,才发现这是Firefox和Geckodriver之间的版本冲突.但是没有人提供如何选择兼容版本的解决方案.这是我的问题.感谢您的帮助.
I searched the internet and only found that this is a version conflict between Firefox and Geckodriver. But nobody gives the solution how to choose the compatible versions. This is my problem. Any help is appreciated.
推荐答案
在注释中进行所有讨论之后,您似乎似乎错了下载 GeckoDriver 的命令,并且可能下载和/或安装时遇到了一些问题 Firefox .
After all the discussion within the comments it seems you erred the command to download GeckoDriver and possibly some issues with downloading and/or installing Firefox.
在内安装 geckodriver 的命令href ="/questions/tagged/ubuntu" class ="post-tag" title =显示标记了'ubuntu'"的问题rel ="tag"> ubuntu 容易出错:
The command to install geckodriver within ubuntu was error prone:
!apt install firefox-geckodriver
以下是详细步骤:
-
浏览到 geckodriver版本页面.检查适用于您平台的 GeckoDriver 的兼容版本,并按以下方式下载:
Browse to the geckodriver releases page. Checkout the compatible version of GeckoDriver for your platform and download it as follows:
wget https://github.com/mozilla/geckodriver/releases/download/v0.24.0/geckodriver-v0.24.0-linux64.tar.gz
使用以下方法提取文件:
Extract the file with:
tar -xvzf geckodriver*
使其可执行:
Make it executable:
chmod +x geckodriver
将驱动程序添加到您的PATH中,以便其他工具可以找到它:
Add the driver to your PATH so other tools can find it:
export PATH=$PATH:/path-to-extracted-file/.
Firefox
Firefox的所有受支持版本中始终提供最新版本的Firefox作为安全更新,并且将安装常规更新.您需要启用安全性或更新存储库(例如Software & Updates
-> Updates
).您需要默认启用Security
,但最好检查软件包管理器是否默认不更新Firefox.
Firefox
The latest version of Firefox is always available as a security updates in all supported releases of Ubuntu and a normal update will install it. You need to enable the security or you need to update the repositories (e. g. Software & Updates
-> Updates
). You need to enable the Security
by default but better to check if the package manager doesn't updates Firefox by default.
您可以在以下位置找到详细步骤:
You can find the detailed steps in:
- Firefox新版本-社区帮助Wiki
- https://askubuntu.com/questions/181607/how-to-install-thunderbird-15-on-ubuntu-12-04
- Firefox New Version - Community Help Wiki
- https://askubuntu.com/questions/181607/how-to-install-thunderbird-15-on-ubuntu-12-04
更新
Selenium Client Driver 页面提到:
Update
Selenium Client Driver page mentions:
-
支持的Python版本:
Supported Python Versions:
Python 2.7, 3.4+
但是硒3.141.0 页面上的列表仅包括:
But the list on selenium 3.141.0 page includes only:
- Python :: 2.7
- Python :: 3.4
- Python :: 3.5
- Python :: 3.6
因此可能仍不支持 Python 3.7 ,您可能必须降级到相关版本.
So possibly Python 3.7 is still not supported and you may have to downgrade to a relevant version.
SessionNotCreatedException:消息:无法创建新服务:带有Selenium 3.14.0和Python 3.7.3的ChromeDriverService
这篇关于WebDriverException:消息:无效参数:无法通过Ubuntu上的Google Colab中的Selenium GeckoDriver和Firefox杀死已退出的进程错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!