您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

如何在OperaDriver中启用内置VPN?

如何在OperaDriver中启用内置VPN?

您正尝试从https://seleniumhq.github.io/selenium/docs/api/py/webdriver_opera/selenium.webdriver.opera.webdriver.html使用OperaOptions而不是ChromeOptions

options:这需要一个ChromeOptions的实例

正如卡乔所说

“从GUI启用VPN,设置已保存在活动配置文件中。”

from selenium import webdriver
from 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 try
IPv6: 2001:67c:2660:425:2:0:0:3f8
IPv4: 77.111.247.26

Second try
IPv6: 2001:67c:2660:425:1a:0:0:1a0
IPv4: 77.111.247.66

Third try
IPv4: 77.111.247.133
IPv6: Not detected

Forth try
IPv6: 2001:67c:2660:425:1c:0:0:1fe
IPv4: 77.111.247.68

我的IP都没有,VPN图标也显示在地址栏旁边。

以回应问题。

来自https://techdows.com/2016/08/opera-profile- location.html

知道Opera的配置文件路径的简单方法是在地址栏中键入about:// about,然后检查路径下的Profile行。

在Windows 10上,代码如下所示。

from selenium import webdriver
from 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\\Programs\Opera\\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()
其他 2022/1/1 18:27:34 有473人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶