Skip to main content
 首页 » 编程设计

python之Selenium 蟒: open default profile in opera

2024年11月01日13dudu

如何在 Opera 中打开默认配置文件? 我的意思是和我在歌剧院打开展台时一样的轮廓。 此代码只是打开了一个新的配置文件:

import os 
from selenium import webdriver 
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities 
os.environ["SELENIUM_SERVER_JAR"] = '/home/brian/bin/selenium-server-standalone-2.37.0.jar' 
capabilities = DesiredCapabilities.OPERA 
capabilities['opera.profile'] = ''   
browser = webdriver.Opera(desired_capabilities=capabilities) 

请您参考如下方法:

基本上,您可以像使用 Chrome 一样设置配置文件。

from selenium import webdriver 
opera_profile = 'C:\\Users\\<username>\\AppData\\roaming\Opera software\\Opera Stable'  # relevant for Windows 7 and above 
options = webdriver.ChromeOptions() 
options.add_argument('user-data-dir=' + opera_profile) 
opera_driver = webdriver.Opera(executable_path=<path_to_operadriver>, opera_options=options)