selenium+chrome options
Environment: selenium chrome
1. selenium + chrome parameters
1.1. Start
from selenium import webdriver
def test_selenium():
#url = 'http://127.0.0.1:9000/spider/'
ch_opt = webdriver.ChromeOptions()
ch_opt.add_argument('lang=zh_CN.UTF-8')
browser = webdriver.Chrome(ch_opt)
# get page
res = browser.get(url)
Concern is webdriver.ChromeOptions () class, which is an alias chrome.options class.
from .chrome.webdriver import WebDriver as Chrome # noqa
from .chrome.options import Options as ChromeOptions # noqa
1.2. options
Source:
# .\Lib\site-packages\selenium\webdriver\chrome\options.py
class Options(object):
def __init__(self):
self._binary_location = '' # Set binary chrome location
self._arguments = [] # parameters the Enabler
self._extension_files = [] # Extended Application added
self._extensions = []
self._experimental_options = {} # Add the experimental setup parameters
self._debugger_address = None # Set the debugger address
1.3. Common settings
1.3.1. useragent
# By providing user-agent, to simulate a mobile device
user_ag='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'
options.add_argument('user-agent=%s'%user_ag)
# Simulation iPhone 6
options.add_argument('user-agent="Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1"')
1.3.2. 3.3. Prohibition image loading
Without loading the pictures, we can improve the crawling speed.
# From loading images
from selenium import webdriver
chrome_options = webdriver.ChromeOptions()
prefs = {"profile.managed_default_content_settings.images": 2}
chrome_options.add_experimental_option("prefs", prefs)
# Start your browser, and set the wait
browser = webdriver.Chrome(chrome_options=chrome_options)
browser.set_window_size (configure.windowHeight, configure.windowWidth) # determined according to desktop resolution, mainly in order to catch a verification code screenshot
wait = WebDriverWait(browser, timeout = configure.timeoutMain)
2. CHROME
2.1. Chrome address bar commands
In the Chrome browser address bar, enter the following command will return the results. These commands include view memory status, browser status, network status, DNS server status, plug-in cache and so on. But note that these commands will not stop change, not always so easy to use.
about: version - Displays the current version
about: memory - display native browser memory usage
about: plugins - Displays the plug-in installation
about: histograms - Show History
about: dns - Displays the DNS status
about: cache - cached page display
about: gpu - whether hardware acceleration
about: flags - so many things pop open some plug-ins after // Use: "Careful, these experiments may", I wonder if I will not mess up the configuration ah!
chrome: // extensions / - extension to view installed
2.2. Chrome practical parameters
Some other practical parameters on Chrome and brief instructions in Chinese, using the method above 4.5.4, of course, can also be used in the shell.
-user-data-dir = "[PATH]" User Data specified user folder path, the user can bookmark data thus stored in the partition other than the system partition.
-disk-cache-dir = "[PATH]" path specified cache Cache
-disk-cache-size = Cache specified size in Byte
-first run reset to the initial state, the first run
-incognito stealth mode is activated
–disable-javascript 禁用Javascript
-omnibox-popup-count = "num" number of the address bar will prompt the pop-up menu instead of num. I have replaced the 15.
-user-agent = "xxxxxxxx" Agent string modified HTTP request header, can be about: See page version Modifying Effects
-disable-plugins from loading all plug-ins, you can increase the speed. It can be about: plugins page View results
-disable-javascript disabled JavaScript, if you feel slow in this together
-disable-java java disabled
-start-maximized to maximize boot
-no-sandbox sandbox mode canceled
-single-process single process run
-process-per-tab Each tag uses a separate process
-process-per-site using a separate process for each site
-in-process-plugins plug-in does not enable separate process
-disable-popup-blocking disable popup interception
-disable-plugins disable the plug
-disable-images disabled image
-incognito boot into stealth mode
-enable-udd-profiles enable the menu to switch accounts
-proxy-pac-url using proxy pac [via 1/2]
-lang = zh-CN set the language to Simplified Chinese
-disk-cache-dir custom cache directory
-disk-cache-size custom cache maximum value (in byte)
-media-cache-size Custom Display maximum cache (in byte)
-bookmark-menu to add a bookmark button in the toolbar
-enable-sync to enable bookmark sync
-single-process single process running Google Chrome
-start-maximized to maximize launch Google Chrome
-disable-java Java ban
-no-sandbox non-sandbox mode
Common:
-single-process single process running Google Chrome
-start-maximized to maximize launch Google Chrome
-disable-java Java ban
-no-sandbox non-sandbox mode