selenium + options Profiles

from selenium.webdriver.chrome.options Import the Options
 from Selenium Import the webdriver 

chrome_options = the Options ()                 # simulator to 
chrome_options.add_argument ( ' --headless ' )           # Browser does not provide visual page 
chrome_options.add_argument ( ' --disable-GPU ' )         # Google documents mentioned the need to add this property to avoid bug 

# set developer mode is activated, webdriver property in this mode is the normal general anti-climb better web site will be based on the anti-climb 
options.add_experimental_option ( ' excludeSwitches ' , [ ' enable-Automation' ]) 

Driver = webdriver.Chrome (chrome_options = chrome_options) # configuration file is loaded into the webdriver
driver.get (' xxxxxx ')

 

If you want to selenium some configuration, then the import options to configure the above must be configured

There is a demand can then add the following configuration

# Because each selenium are using the Open browser without the browser configuration, this is to allow selenium and my favorite browser configuration, like, ccokies and plug-ins will record 
# configuration file path than the path I see widows can try in Chrome enter chrome: // version / profile path is 
chrome_options.add_argument ( " --user-the data-dir = " + r " C: \\ the Users \\ AppData \\ Local Administrator \\ \\ \\ Google Chrome \ \ \\ the Default the Data the User " ) 

# no load pictures to enhance the speed 
options.add_argument ( ' Blink-Settings = imagesEnabled = false ' ) 

# add UA 
options.add_argument ( 'user-agent = "MQQBrowser / 26 Mozilla / 5.0 (Linux; U; Android 2.3.7; zh-cn; MB200 Build / GRJ22; CyanogenMod-7) AppleWebKit / 533.1 (KHTML, like Gecko) Version / 4.0 Mobile Safari / 533.1 ' ' ) 

# scroll bar is hidden, to deal with some special pages 
options.add_argument ( ' --hide-scrollbars ' ) 

# to run with highest privileges 
options.add_argument ( ' --no-Sandbox ' ) 

# disable JavaScript 
option.add_argument ( " - JavaScript--disable " ) 

# disable the browser pop 
Prefs = { 
 ' profile.default_content_setting_values ' : { 
 'notifications' : 2 
} } 
options.add_experimental_option('prefs',prefs)

 

Guess you like

Origin www.cnblogs.com/zengxm/p/10963947.html