简体   繁体   English

selenium.common.exceptions.WebDriverException:消息:未知错误:无法使用 OperaDriver Selenium 和 Python 找到 Opera 二进制文件

[英]selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Opera binary with OperaDriver Selenium and Python

I just tried to get an easy Python script to work, which should only open up google.我只是试图让一个简单的 Python 脚本工作,它应该只打开 google。

I installed selenium with pip and placed the operadriver, downloaded from the selenium page, into my python path.我用 pip 安装了 selenium 并将从 selenium 页面下载的operadriver放入我的python路径中。 Also watched many videos about it, but I can't find a solution..也看了很多关于它的视频,但我找不到解决方案..

Here's the code:这是代码:

from selenium import webdriver
import time

driver = webdriver.Opera()
driver.get('http://www.google.com')

The error:错误:

Traceback (most recent call last):
  File "C:/Users/Tom/AppData/Local/Programs/Python/Python37-32/Scripts/automate.py", line 4, in <module>
    driver = webdriver.Opera()
  File "C:\Users\Tom\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\opera\webdriver.py", line 83, in __init__
    service_log_path=service_log_path)
  File "C:\Users\Tom\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\opera\webdriver.py", line 62, in __init__
    keep_alive=keep_alive)
  File "C:\Users\Tom\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 81, in __init__
    desired_capabilities=desired_capabilities)
  File "C:\Users\Tom\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 157, in __init__
    self.start_session(capabilities, browser_profile)
  File "C:\Users\Tom\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 252, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "C:\Users\Tom\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "C:\Users\Tom\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Opera binary
  (Driver info: OperaDriver=2.40 (a50783a565882ef2022bea655e8560f37ecf8afe),platform=Windows NT 6.1.7601 SP1 x86_64)

This error message...这个错误信息...

selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Opera binary
  (Driver info: OperaDriver=2.40 (a50783a565882ef2022bea655e8560f37ecf8afe),platform=Windows NT 6.1.7601 SP1 x86_64)

...implies that the Opera Browser binary wasn't found at the required location. ...暗示在所需位置未找到Opera 浏览器二进制文件。

Your main issue is the Opera Browser is not installed at the default location.您的主要问题是Opera 浏览器未安装在默认位置。 So you need to mention the absolute path of the location where Opera Browser is installed as follows:所以需要提一下Opera浏览器安装位置的绝对路径如下:

from selenium import webdriver
from selenium.webdriver.opera.options import Options

options = Options()
options.binary_location = r'C:\path\to\opera.exe'
driver = webdriver.Opera(opera_options = options, executable_path=r'C:\Utility\BrowserDrivers\operadriver.exe')
driver.get('http://www.google.com')

The simple solution for me: I have a Feedscode folder where my chromedriver.exe and my operadriver.exe reside in my downloads folder where I run the file.ipynb files.对我来说简单的解决方案:我有一个 Feedscode 文件夹,其中我的 chromedriver.exe 和我的 operadriver.exe 位于我运行 file.ipynb 文件的下载文件夹中。

The error is pretty obvious it is looking in the wrong place for the opera.exe this issue started for me after opera updated to 73.0.3856.257_0 this is the latest opera folder update as of 12/14/2020.这个错误很明显,它在错误的地方寻找opera.exe 这个问题是在Opera更新到73.0.3856.257_0之后开始的,这是截至2020年12月14日的最新opera文件夹更新。

What I did to fix opera was I took C:\\Users\\your_user_name_here\\AppData\\Local\\Programs\\Opera\\73.0.3856.257_0 folder and simply copied the folder 73.0.3856.257_0 to my downloads\\feedscode folder I then copied my .ipynb files and my operadriver.exe and chromedriver.exe files to the 73.0.3856.257_0 folder then I made this one change before I ran the process.我为修复歌剧所做的工作是将 C:\\Users\\your_user_name_here\\AppData\\Local\\Programs\\Opera\\73.0.3856.257_0 文件夹复制到我的 downloads\\feedscode 文件夹,然后复制我的 .ipynb文件和我的operadriver.exe 和chromedriver.exe 文件到73.0.3856.257_0 文件夹,然后我在运行该过程之前进行了这一更改。

chrome_path = "C:\\Users\\User_name_here\\Downloads\\FeedsCode\\73.0.3856.257_0\\operadriver.exe" chrome_path = "C:\\Users\\User_name_here\\Downloads\\FeedsCode\\73.0.3856.257_0\\operadriver.exe"

Now the process works as expected.现在该过程按预期工作。

So the error clearly is due to the fact it is looking for opera.exe in the folder that the operadriver.exe is located in. You have 2 options 1. Wait for a fix or 2. Do as I have shown above.因此,该错误显然是由于它正在operadriver.exe 所在的文件夹中查找opera.exe。您有2 个选项1. 等待修复或2. 按照我上面显示的操作。

I am sure this will help many as the original answer here did not work for me everyone enjoy.我相信这会对很多人有所帮助,因为这里的原始答案并不适合每个人都喜欢的我。

Note the chromedriver.exe does not have this problem, so you can simply use chromedriver.exe instead of operadriver.exe.注意 chromedriver.exe 没有这个问题,所以你可以简单地使用 chromedriver.exe 而不是operadriver.exe。 I also notice in the Opera update when we run the process it will work fine as long as the process window remains on the screen if we go to another task window it will stop until you open the process screen back up.我还注意到在 Opera 更新中,当我们运行进程时,只要进程窗口保持在屏幕上,如果我们转到另一个任务窗口,它将停止,直到您打开进程屏幕备份。 THIS DOES NOT HAPPEN with chromedriver.exe only the latest operadriver.exe and Opera update as of 12/14/2020.这不会发生在 chromedriver.exe 上,只有 2020 年 14 月 12 日最新的 operadriver.exe 和 Opera 更新。

Note there is an advantage to my suggested fix and that is the Opera Browser will not automatically update since we copied the entire 73.0.3856.257_0 folder to a different location you would have to copy the latest Opera updated folder manually, so you won't be stung by an update unexpectedly.请注意,我建议的修复有一个优势,那就是 Opera 浏览器不会自动更新,因为我们将整个 73.0.3856.257_0 文件夹复制到了不同的位置,您必须手动复制最新的 Opera 更新文件夹,因此您不会意外地被更新刺痛了。

暂无
暂无

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

相关问题 Selenium 在 Mac 上给出“selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Chrome binary” - Selenium gives "selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Chrome binary" on Mac Selenium.common.exceptions.WebDriverException:消息:未知错误:没有 chrome 二进制文件 - Selenium.common.exceptions.WebDriverException: Message: unknown error: no chrome binary raise exception_class(message, screen, stacktrace) selenium.common.exceptions.WebDriverException:消息:未知错误:找不到 Chrome 二进制文件 - raise exception_class(message, screen, stacktrace) selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Chrome binary selenium.common.exceptions.WebDriverException:消息:未知错误:Chrome 无法启动:在 Python 中使用 ChromeDriver 和 Selenium 崩溃 - selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: crashed with ChromeDriver and Selenium in Python selenium.common.exceptions.WebDriverException:消息:未知错误:无法使用带有Selenium Python的ChromeDriver Chrome创建Chrome进程 - selenium.common.exceptions.WebDriverException: Message: unknown error: Failed to create Chrome process with ChromeDriver Chrome with Selenium Python Python(Selenium):selenium.common.exceptions.WebDriverException:消息:处理指定命令时发生未知错误 - Python (Selenium): selenium.common.exceptions.WebDriverException: Message: An unknown error occurred while processing the specified command selenium.common.exceptions.WebDriverException:消息:未知错误:无法使用镓和Docker杀死Chrome错误 - selenium.common.exceptions.WebDriverException: Message: unknown error: cannot kill Chrome error with gallium and Docker selenium.common.exceptions.WebDriverException:消息:未知错误:无法聚焦元素,slenium - selenium.common.exceptions.WebDriverException: Message: unknown error: cannot focus element, slenium selenium.common.exceptions.WebDriverException:消息:未知错误:无法在 localhost:8733 \\\\ 连接到 chrome 怎么回事? - selenium.common.exceptions.WebDriverException: Message: unknown error: cannot connect to chrome at localhost:8733 \\\\ What's going on? selenium.common.exceptions.WebDriverException:消息:在 Python selenium 4 - selenium.common.exceptions.WebDriverException: Message: in Python selenium 4
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM