selenium.common.exceptions.WebDriverException:消息:未知错误:无法使用OperaDriver Selenium和Python找到Opera二进制文件 [英] selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Opera binary with OperaDriver Selenium and Python

查看:183
本文介绍了selenium.common.exceptions.WebDriverException:消息:未知错误:无法使用OperaDriver Selenium和Python找到Opera二进制文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想让一个简单的Python脚本正常工作,应该只打开google.

I just tried to get an easy Python script to work, which should only open up google.

我用pip安装了selenium,并将从selenium页面下载的Operadriver放入了我的python路径.还看了很多关于它的视频,但是我找不到解决方法.

I installed selenium with pip and placed the operadriver, downloaded from the selenium page, into my python path. Also watched many videos about it, but I can't find a solution..

代码如下:

from selenium import webdriver
import time

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

错误:

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)

推荐答案

此错误消息...

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)

...表示在所需位置找不到 Opera Browser 二进制文件.

...implies that the Opera Browser binary wasn't found at the required location.

您的主要问题是未在默认位置安装 Opera浏览器.因此,您需要提及 Opera浏览器的安装位置的绝对路径,如下所示:

Your main issue is the Opera Browser is not installed at the default location. So you need to mention the absolute path of the location where Opera Browser is installed as follows:

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

这篇关于selenium.common.exceptions.WebDriverException:消息:未知错误:无法使用OperaDriver Selenium和Python找到Opera二进制文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆