简体   繁体   English

geckodriver 的 Google Colaboratory 中的 executable_path 是什么?

[英]What is the executable_path in Google Colaboratory for geckodriver?

I want to use geckodriver in Google Colaboratory with Selenium Python package.我想在带有 Selenium Python 包的 Google Colaboratory 中使用 geckodriver。 Here is what I tried (I'm not an expert in Ubuntu)这是我尝试过的(我不是 Ubuntu 专家)

!pip install selenium
!apt-get update 
!apt install firefox-geckodriver
from selenium.webdriver.firefox.options import Options as FirefoxOptions

firefox_options = FirefoxOptions()
firefox_options.add_argument("--headless")
driver = webdriver.Firefox(executable_path=r'/usr/bin/firefox', options=firefox_options)

Here r'/usr/bin/firefox is wrong.这里r'/usr/bin/firefox是错误的。 I'm confused.我糊涂了。 What can be the solution?解决办法是什么? Any help is appreciated.任何帮助表示赞赏。

executable_path可执行路径

executable_path is the parameter through which users can pass the absolute path of the GeckoDriver binary overriding the system path of GeckoDriver binary to be used for Firefox 47.0.1 and greater. executable_path是通过它用户可以通过GeckoDriver绝对路径二进制重写GeckoDriver二进制的系统路径用于火狐47.0.1和更大的参数。

Example例子

from selenium import webdriver
from selenium.webdriver.firefox.options import Options

options = Options()
options.add_argument("start-maximized")
options.add_argument("--headless")
driver = webdriver.Firefox(options=options, executable_path=r'C:\Utility\BrowserDrivers\geckodriver.exe')
driver.get("http://google.com/")

But in your code trials you have passed the absolute path of the Firefox binary instead of the GeckoDriver binary.但是在您的代码试验中,您传递了Firefox二进制文件的绝对路径,而不是GeckoDriver二进制文件。 If your usecase is to pass the absolute path of the Firefox binary as well you can use the following line of code:如果您的用例也是传递Firefox二进制文件的绝对路径,您可以使用以下代码行:

from selenium import webdriver

binary = r'C:\Program Files\Mozilla Firefox\firefox.exe'
options = webdriver.FirefoxOptions()
options.binary = binary
options.add_argument("start-maximized")
options.add_argument("--headless")
browser = webdriver.Firefox(firefox_options=options, executable_path="C:\\Utility\\BrowserDrivers\\geckodriver.exe")
browser.get('http://google.com/')

GeckoDriver in Google-Colaboratory Google-Colaboratory 中的 GeckoDriver

You need to install the geckodriver, firefox and selenium and add the path to your path variable within your system or copy within the bin directory and you can use the following solution:您需要安装 geckodriver、firefox 和 selenium 并将路径添加到系统中的路径变量或复制到 bin 目录中,您可以使用以下解决方案:

# 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/')

Update 1更新 1

As per the error you mentioned within the comments, as you are using ipython the options should be passed within single quotes as start-maximized and --headless .根据您在评论中提到的错误,当您使用ipython ,选项应在单引号内作为start-maximized--headless Additionally, while specifying executable_path there shouldn't be any space character between the raw string literals marker and the string此外,在指定executable_pathraw string literals markerstring之间不应有任何空格字符

You can find a relevant discussion in SyntaxError: invalid syntax with executable_path in ipython您可以在SyntaxError: invalid syntax with executable_path in ipython 中找到相关讨论


Update 2更新 2

For GeckoDriver , Selenium and Firefox Browser compatibility chart you can find a relevant discussion in WebDriverException: Message: invalid argument: can't kill an exited process with GeckoDriver, Selenium and Python on RaspberryPi3对于GeckoDriverSeleniumFirefox 浏览器兼容性图表,您可以在WebDriverException: Message: invalid argument: can't kill an exited process with GeckoDriver, Selenium 和 Python on RaspberryPi3 中找到相关讨论

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 dyld:库未加载:@executable_path/../.Python - dyld: Library not loaded: @executable_path/../.Python 消息:“geckodriver”可执行文件需要在 PATH 中 - Message: 'geckodriver' executable needs to be in PATH WebDriverException:消息:“chromedriver”可执行文件需要在 PATH 中使用 Google Colaboratory 上的 python 语言 - WebDriverException: Message: 'chromedriver' executable needs to be in PATH using python language on Google Colaboratory 弃用警告:executable_path 已被弃用,请传入一个 Service 对象 - DeprecationWarning: executable_path has been deprecated, please pass in a Service object GeckoDriver 必须在在线服务器(wayscript.com)的可执行路径中 - GeckoDriver must be in executable path in online server(wayscript.com) 在 Google Colaboratory 上运行 faiss - Running faiss on Google Colaboratory 尝试使用 selenium (Python) 打开 Firefox 时出现两个错误; 系统找不到指定的文件; Geckodriver 可执行文件需要在 PATH 中 - Two errors when trying to open firefox using selenium (Python); System cannot find the file specified; Geckodriver executable needs to be in PATH 在 Google Colaboratory 上访问 Google 表格 - Access Google Sheets on Google Colaboratory 关于 Google Colaboratory 在 javascript 上的错误 - about Google Colaboratory errot at javascript 如何在 Colaboratory Google 上使用 Selenium? - How to use Selenium on Colaboratory Google?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM