您正尝试从https://seleniumhq.github.io/selenium/docs/api/py/webdriver_opera/selenium.webdriver.opera.webdriver.html使用OperaOptions而不是ChromeOptions
options:这需要一个ChromeOptions的实例
正如卡乔所说
“从GUI启用VPN,设置已保存在活动配置文件中。”
from selenium import webdriverfrom time import sleep# The profile where I enabled the VPN previously using the GUI.opera_profile = '/home/dan/.config/opera' options = webdriver.ChromeOptions()options.add_argument('user-data-dir=' + opera_profile)driver = webdriver.Opera(options=options)driver.get('https://whatismyipaddress.com')sleep(10)driver.quit()结果:
First tryIPv6: 2001:67c:2660:425:2:0:0:3f8IPv4: 77.111.247.26Second tryIPv6: 2001:67c:2660:425:1a:0:0:1a0IPv4: 77.111.247.66Third tryIPv4: 77.111.247.133IPv6: Not detectedForth tryIPv6: 2001:67c:2660:425:1c:0:0:1feIPv4: 77.111.247.68
我的IP都没有,VPN图标也显示在地址栏旁边。
更新 以回应问题。
来自https://techdows.com/2016/08/opera-profile-
location.html
知道Opera的配置文件路径的简单方法是在地址栏中键入about:// about,然后检查路径下的Profile行。
在Windows 10上,代码如下所示。
from selenium import webdriverfrom time import sleep# The profile where I enabled the VPN previously using the GUI.opera_profile = r'C:\Users\dan\AppData\Roaming\Opera Software\Opera Stable' options = webdriver.ChromeOptions()options.add_argument('user-data-dir=' + opera_profile)options._binary_location = r'C:\Users\dan\AppData\Local\ProgramsOpera\58.0.3135.114\opera.exe'driver = webdriver.Opera(executable_path=r'C:\operadriver_win64\operadriver.exe',options=options)driver.get('https://whatismyipaddress.com')sleep(10)driver.quit()


