--ignore-certificate-errors
--allow-running-insecure-content
啟動(dòng)參數(shù):
--User-data-dir="UserData"
設(shè)置用戶目錄;
--disk-cache-dir="%Temp%\Chrome"
設(shè)置緩存目錄;
--enable-extensions
啟動(dòng)用戶擴(kuò)展;
--enable-user-scripts
啟用用戶腳本。
# 加載local的Chrome配置
options = webdriver.ChromeOptions()
options.add_argument(r'--user-data-dir=C:\Users\ditto.he\AppData\Local\Google\Chrome\User Data')
options.add_argument('disable-infobars')
options.add_argument('--ignore-certificate-errors')
# options.add_experimental_option("excludeSwitches", ["ignore-certificate-errors"])
driver = webdriver.Chrome(chrome_options=options)
'''#模仿手機(jī)
option = webdriver.ChromeOptions()
# 偽裝iphone登錄
# option.add_argument('--user-agent=iphone')
# 偽裝android
option.add_argument('--user-agent=android')
driver = webdriver.Chrome(chrome_options=option)
#自己下載的crx路徑#加插件
option.add_extension('d:\crx\AdBlock_v2.17.crx')
# 設(shè)置下載路徑
chromeOptions = webdriver.ChromeOptions()
prefs = {"download.default_directory": "/path/download"}
chromeOptions.add_experimental_option("prefs", prefs)
driver = webdriver.Chrome(executable_path=chromedriver, chrome_options=chromeOptions)
# 設(shè)置代理
PROXY = "23.23.23.23:3128" # IP:PORT or HOST:PORT
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--proxy-server=http://%s' % PROXY)
chrome = webdriver.Chrome(chrome_options=chrome_options)
chrome.get("http://whatismyipaddress.com")
'''
####headless模式####
# -*- coding: utf-8 -*-
from selenium import webdriver
from time import sleep
mobileEmulation = {'deviceName': 'Apple iPhone 4'}
options = webdriver.ChromeOptions()
options.add_argument("--headless")#設(shè)置為 headless 模式
options.add_argument("--window-size=100,100")#設(shè)置窗口大小
options.add_experimental_option('mobileEmulation', mobileEmulation)
driver = webdriver.Chrome(chrome_options=options)
driver.get('http://m.baidu.com')
sleep(3)
# driver.close()
####模仿手機(jī)####
# -*- coding: utf-8 -*-
# from selenium import webdriver
# from time import sleep
# WIDTH = 320
# HEIGHT = 640
# PIXEL_RATIO = 3.0
# UA = 'Mozilla/5.0 (Linux; Android 4.1.1; GT-N7100 Build/JRO03C) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/35.0.1916.138 Mobile Safari/537.36 T7/6.3'
# mobileEmulation = {"deviceMetrics": {"width": WIDTH, "height": HEIGHT, "pixelRatio": PIXEL_RATIO}, "userAgent": UA}
# options = webdriver.ChromeOptions()
# options.add_experimental_option('mobileEmulation', mobileEmulation)
# driver = webdriver.Chrome(chrome_options=options)
# driver.get('http://m.baidu.com')
# sleep(3)
# driver.close()
目前我封裝是這樣配置的
options=webdriver.ChromeOptions()
options.add_argument(r'--user-data-dir=C:\Users\ditto.he\AppData\Local\Google\Chrome\User Data')
options.add_argument('disable-infobars')
options.add_argument('--ignore-certificate-errors')
driver=webdriver.Chrome(chrome_options=options)
注意引號(hào)后有空格
options.add_argument("--lang=" + "zh-CN")
#切換瀏覽器語(yǔ)言
options.add_argument("--test-type", "--ignore-certificate-errors")
#忽略 Chrome 瀏覽器證書錯(cuò)誤報(bào)警提示
DesiredCapabilities capabilities = DesiredCapabilities.chrome()
capabilities.setCapability("chrome.switches", Arrays.asList("--start-maximized"))
options.addArguments("--test-type", "--start-maximized","no-default-browser-check")
#意思好像是測(cè)試模式,最大化瀏覽器并且默認(rèn)不檢查瀏覽器
options.addExtensions(new File("C:\\Users\\username\\AppData\\Local\\Google\\Chrome\\UserData\\Default\\Extensions\\ijaobnmmgonppmablhldddpfmgpklbfh\\1.6.0_0.crx"))
#添加擴(kuò)展的方法,將crx文件所在的路徑添加進(jìn)去
序號(hào) 參數(shù) 說明
1 --allow-outdated-plugins 不停用過期的插件。
2 --allow-running-insecure-content 默認(rèn)情況下,https 頁(yè)面不允許從 http 鏈接引用 javascript/css/plug-ins。添加這一參數(shù)會(huì)放行這些內(nèi)容。
3 --allow-scripting-gallery 允許拓展腳本在官方應(yīng)用中心生效。默認(rèn)情況下,出于安全因素考慮這些腳本都會(huì)被阻止。
4 --disable-accelerated-video 停用 GPU 加速視頻。
5 --disable-dart 停用 Dart。
6 --disable-desktop-notifications 禁用桌面通知,在 Windows 中桌面通知默認(rèn)是啟用的。
7 --disable-extensions 禁用拓展。
8 --disable-file-system 停用 FileSystem API。
9 --disable-preconnect 停用 TCP/IP 預(yù)連接。
10 --disable-remote-fonts 關(guān)閉遠(yuǎn)程字體支持。SVG 中字體不受此參數(shù)影響。
11 --disable-speech-input 停用語(yǔ)音輸入。
12 --disable-web-security 不遵守同源策略。
13 --disk-cache-dir 將緩存設(shè)置在給定的路徑。
14 --disk-cache-size 設(shè)置緩存大小上限,以字節(jié)為單位。
15 --dns-prefetch-disable 停用DNS預(yù)讀。
16 --enable-print-preview 啟用打印預(yù)覽。
17 --extensions-update-frequency 設(shè)定拓展自動(dòng)更新頻率,以秒為單位。
18 --incognito 讓瀏覽器直接以隱身模式啟動(dòng)。
19 --keep-alive-for-test 最后一個(gè)標(biāo)簽關(guān)閉后仍保持瀏覽器進(jìn)程。(某種意義上可以提高熱啟動(dòng)速度,不過你最好得有充足的內(nèi)存)
20 --kiosk 啟用kiosk模式。(一種類似于全屏的瀏覽模式)
21 --lang 使用指定的語(yǔ)言。
22 --no-displaying-insecure-content 默認(rèn)情況下,https 頁(yè)面允許從 http 鏈接引用圖片/字體/框架。添加這一參數(shù)會(huì)阻止這些內(nèi)容。
23 --no-first-run 跳過 Chromium 首次運(yùn)行檢查。
24 --no-referrers 不發(fā)送 Http-Referer 頭。
25 --no-sandbox 徹底停用沙箱。
26 --no-startup-window 啟動(dòng)時(shí)不建立窗口。
27 --proxy-pac-url 使用給定 URL 的 pac 代理腳本。(也可以使用本地文件,如 --proxy-pac-url="file:\\\c:\proxy.pac")
28 --proxy-server 使用給定的代理服務(wù)器,這個(gè)參數(shù)只對(duì) http 和 https 有效。(例如 --proxy-server=127.0.0.1:8087 )
29 --single-process 以單進(jìn)程模式運(yùn)行 Chromium。(啟動(dòng)時(shí)瀏覽器會(huì)給出不安全警告)
30 --start-maximized 啟動(dòng)時(shí)最大化。
31 --user-agent 使用給定的 User-Agent 字符串
參數(shù):--user-data-dir=UserDataDir
用途:自訂使用者帳戶資料夾(如:–user-data-dir="D:\temp\Chrome User Data")
參數(shù):--process-per-tab
用途:每個(gè)分頁(yè)使用單獨(dú)進(jìn)程
參數(shù):--process-per-site
用途:每個(gè)站點(diǎn)使用單獨(dú)進(jìn)程
參數(shù):--in-process-plugins
用途:插件不啟用單獨(dú)進(jìn)程
參數(shù):--disable-popup-blocking
用途:禁用彈出攔截
參數(shù):--disable-javascript
用途:禁用JavaScript
參數(shù):--disable-java
用途:禁用Java
參數(shù):--disable-plugins
用途:禁用插件
參數(shù):–disable-images
用途:禁用圖像
參數(shù):--omnibox-popup-count=”num”
用途:將網(wǎng)址列彈出的提示選單數(shù)量改為num個(gè)
參數(shù):--enable-vertical-tabs
用途:調(diào)整chrome游覽器標(biāo)簽存放在左邊,非頂部
嗯chrome配置就醬紫了
覺得奇怪總是能打開chrome但是不能打開網(wǎng)頁(yè)
報(bào)錯(cuò)如下:selenium.common.exceptions.WebDriverException: Message: unknown error: unable to discover open pages
(Driver info: chromedriver=2.29.461591 (62ebf098771772160f391d75e589dc567915b233),platform=Windows NT 6.1.7601 SP1 x86_64)
*****明明是對(duì)的版本==明明我js執(zhí)行測(cè)試腳本時(shí)都能打開chrome*****思考ing
59配29的driver
Extension Automation 能夠監(jiān)視網(wǎng)頁(yè)地址自動(dòng)啟用或禁用擴(kuò)展


來源: