Selenium : Opera 需要基于 70 到 73 之间的 Chromium 版本

Selenium : Opera needs to be based on Chromium version between 70 and 73

我对 Selenium 很陌生,所以我希望我的问题不是愚蠢的。 我尝试在 Python 的 Opera 上使用 selenium。但是每次我尝试 运行 我得到这个错误的代码:

"selenium.common.exceptions.WebDriverException: Message: unknown error: cannot connect to Opera at localhost:1212
from session not created: Opera needs to be based on Chromium version between 70 and 73
  (Driver info: OperaDriver=2.45.3255 (O60),platform=Linux 4.15.0-29-generic x86_64)"

我知道Opera 的最后一个版本只使用了60 Chromium 版本。 所以对我来说似乎不可能将 Opera 与 Selenium 一起使用。

但我看到很多人都在使用它......所以我一定是做错了......

from selenium import webdriver
from selenium.webdriver.chrome import service

from bs4 import BeautifulSoup


webdriver_service = service.Service('operadriver_linux64/operadriver')
webdriver_service.start()

capabilities = { 'operaOptions': { 'debuggerAddress': "localhost:1212" }}

driver = webdriver.Remote(webdriver_service.service_url, capabilities)

driver.get('https://www.google.com/')

input_txt = driver.find_element_by_name('q')
input_txt.send_keys('operadriver\n')

soup = BeautifulSoup(driver.page_source, 'html.parser')

print(soup.title.string)
print("---")
for site in soup.find_all('h3'):
    for child in site.children:
        print(child.string)
        print(child['href'])

driver.quit()

这就是我得到的:

  File "test.py", line 14, in <module>
    driver = webdriver.Remote(webdriver_service.service_url, capabilities)  File "/home/ender/.local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
    self.start_session(capabilities, browser_profile)  File "/home/ender/.local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)  File "/home/ender/.local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)  File "/home/ender/.local/lib/python3.6/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 connect to Opera at localhost:1212
from session not created: Opera needs to be based on Chromium version between 70 and 73
  (Driver info: OperaDriver=2.45.3255 (O60),platform=Linux 4.15.0-29-generic x86_64)

关于 Opera 最多只使用 Chromium 60 的说法是错误的。在维基百科上它提到最新的 Opera 版本确实使用 Chromium 70 到 73。

Opera 57 was released on November 28, 2018, based on Chromium 70.
Opera 58 was released on January 23, 2019, based on Chromium 71.
Opera 60 was released on April 9, 2019, based on Chromium 73.
Opera 62 was released on June 27, 2019, based on Chromium 75.

https://en.wikipedia.org/wiki/History_of_the_Opera_web_browser#Opera_2018

您只需要使用 Opera 57 到 60。

这是 FileHippo 上 Opera 60 的 link: https://filehippo.com/download_opera/91340/