我想自动使用Python + Selenium操作Opera。
参考下面的网址,我在下面写了一个脚本。
Drive Opera with selenium python
from selenium import webdriver
from selenium.webdriver.chrome import service
webdriver_service = service.Service('/usr/bin/opera')
webdriver_service.start()
capabilities = { 'operaOptions': { 'debuggerAddress': "localhost:1212" }}
browser = webdriver.Remote(webdriver_service.service_url, webdriver.DesiredCapabilities.OPERA)
response = browser.get('https://www.facebook.com/')
通过此脚本,Opera已启动,但Facebook页面无法打开。
我该如何解决?请帮帮我。
设置如下。
Ubuntu 16.04, Python 3.5.2, Selenium 3.6.0, Opera 49.0
答案 0 :(得分:0)
capabilities = { 'operaOptions': { 'debuggerAddress': "localhost:1212" }}
由于您正在设置此功能,我认为您需要此功能才能访问网络。但是,您没有将其设置为webdriver功能
capabilities = webdriver.DesiredCapabilities.OPERA
capabilities ['operaOptions'] = { 'debuggerAddress': "localhost:1212" }
browser = webdriver.Remote(webdriver_service.service_url, capabilities)
答案 1 :(得分:0)
这是一种简单的方法:
from selenium import webdriver
driver = webdriver.Opera()
driver.get("https://www.facebook.com")
# make sure 'operadriver.exe' is in the same folder as your script
在查找歌剧二进制文件时遇到问题:
from selenium import webdriver
options = webdriver.ChromeOptions()
options.binary_location ="<your opera executable directory>"
driver = webdriver.Opera(options=options)
driver.get("https://www.facebook.com")
# make sure 'operadriver.exe' is in the same folder as your script