溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

Selenium啟動(dòng)Chrome時(shí)配置選項(xiàng)詳解

發(fā)布時(shí)間:2020-10-22 16:52:09 來源:腳本之家 閱讀:727 作者:廖劍秋 欄目:開發(fā)技術(shù)

Selenium操作瀏覽器是不加載任何配置的,網(wǎng)上找了半天,關(guān)于Firefox加載配置的多點(diǎn),Chrome資料很少,下面是關(guān)于加載Chrome配置的方法:

一、加載所有Chrome配置

用Chrome地址欄輸入chrome://version/,查看自己的“個(gè)人資料路徑”,然后在瀏覽器啟動(dòng)時(shí),調(diào)用這個(gè)配置文件,代碼如下:

#coding=utf-8
from selenium import webdriver
option = webdriver.ChromeOptions()
option.add_argument('--user-data-dir=C:\Users\Administrator\AppData\Local\Google\Chrome\User Data') #設(shè)置成用戶自己的數(shù)據(jù)目錄
driver = webdriver.Chrome(chrome_options=option)

二、修改瀏覽器的User-Agent來偽裝你的瀏覽器訪問手機(jī)m站

#coding=utf-8
from selenium import webdriver
option = webdriver.ChromeOptions()
option.add_argument('--user-agent=iphone')
driver = webdriver.Chrome(chrome_options=option)
driver.get('http://www.taobao.com/')

三、瀏覽器啟動(dòng)時(shí)安裝crx擴(kuò)展

#coding=utf-8
from selenium import webdriver
option = webdriver.ChromeOptions()
option.add_extension('d:\crx\AdBlock_v2.17.crx') #自己下載的crx路徑
driver = webdriver.Chrome(chrome_options=option)
driver.get('http://www.taobao.com/')

可以去https://sites.google.com/a/chromium.org/chromedriver/capabilities查看更多,或者去http://stackoverflow.com/查找。

下邊是收集的一些配置信息:

一些Chrome的地址欄命令(這些命令會(huì)不停的變動(dòng),所有不一定都是好用的)

在Chrome的瀏覽器地址欄中輸入以下命令,就會(huì)返回相應(yīng)的結(jié)果。這些命令包括查看內(nèi)存狀態(tài),瀏覽器狀態(tài),網(wǎng)絡(luò)狀態(tài),DNS服務(wù)器狀態(tài),插件緩存等等。
  about:version - 顯示當(dāng)前版本
  about:memory - 顯示本機(jī)瀏覽器內(nèi)存使用狀況
  about:plugins - 顯示已安裝插件
  about:histograms - 顯示歷史記錄
  about:dns - 顯示DNS狀態(tài)
  about:cache - 顯示緩存頁面
  about:gpu -是否有硬件加速
  about:flags -開啟一些插件 //使用后彈出這么些東西:“請(qǐng)小心,這些實(shí)驗(yàn)可能有風(fēng)險(xiǎn)”,不知會(huì)不會(huì)搞亂俺的配置啊!
  chrome://extensions/ - 查看已經(jīng)安裝的擴(kuò)展
  其他的一些關(guān)于Chrome的實(shí)用參數(shù)及簡(jiǎn)要的中文說明(使用方法同上,當(dāng)然也可以在shell中使用)
  –user-data-dir=”[PATH]” 指定用戶文件夾User Data路徑,可以把書簽這樣的用戶數(shù)據(jù)保存在系統(tǒng)分區(qū)以外的分區(qū)。
  –disk-cache-dir=”[PATH]“ 指定緩存Cache路徑
  –disk-cache-size= 指定Cache大小,單位Byte
  –first run 重置到初始狀態(tài),第一次運(yùn)行
  –incognito 隱身模式啟動(dòng)
  –disable-javascript 禁用Javascript
  --omnibox-popup-count="num" 將地址欄彈出的提示菜單數(shù)量改為num個(gè)。我都改為15個(gè)了。
  --user-agent="xxxxxxxx" 修改HTTP請(qǐng)求頭部的Agent字符串,可以通過about:version頁面查看修改效果
  --disable-plugins 禁止加載所有插件,可以增加速度??梢酝ㄟ^about:plugins頁面查看效果
  --disable-javascript 禁用JavaScript,如果覺得速度慢在加上這個(gè)
  --disable-java 禁用java
  --start-maximized 啟動(dòng)就最大化
  --no-sandbox 取消沙盒模式
  --single-process 單進(jìn)程運(yùn)行
  --process-per-tab 每個(gè)標(biāo)簽使用單獨(dú)進(jìn)程
  --process-per-site 每個(gè)站點(diǎn)使用單獨(dú)進(jìn)程
  --in-process-plugins 插件不啟用單獨(dú)進(jìn)程
  --disable-popup-blocking 禁用彈出攔截
  --disable-plugins 禁用插件
  --disable-images 禁用圖像
  --incognito 啟動(dòng)進(jìn)入隱身模式
  --enable-udd-profiles 啟用賬戶切換菜單
  --proxy-pac-url 使用pac代理 [via 1/2]
  --lang=zh-CN 設(shè)置語言為簡(jiǎn)體中文
  --disk-cache-dir 自定義緩存目錄
  --disk-cache-size 自定義緩存最大值(單位byte)
  --media-cache-size 自定義多媒體緩存最大值(單位byte)
  --bookmark-menu 在工具 欄增加一個(gè)書簽按鈕
  --enable-sync 啟用書簽同步

常用:

–single-process 單進(jìn)程運(yùn)行Google Chrome

–start-maximized 啟動(dòng)Google Chrome就最大化

–disable-java 禁止Java

–no-sandbox  非沙盒模式運(yùn)行

全部:(下面的沒有進(jìn)行翻譯,仔細(xì)看下應(yīng)該都看得懂. ~ ~)

–disable-hang-monitor

Suppresses hang monitor dialogs in renderer processes.

–disable-metrics

Completely disables UMA metrics system.

–disable-metrics-reporting

Disables only the sending of metrics reports. In contrast to kDisableMetrics, this executes all the code that a normal client would use for reporting, except the report is dropped rather than sent to the server. This is useful for finding issues in the metrics code during UI and performance tests.

–assert-test

Causes the browser process to throw an assertion on startup.

–renderer-assert-test

Causes the renderer process to throw an assertion on launch.

–crash-test

Performs a crash test when the browser is starte.

–renderer-crash-test

Causes the renderer process to crash on launch.

–renderer-startup-dialog

Use this argument when you want to see the child processes as soon as Chrome start.

–plugin-startup-dialog

Causes the plugin process to display a dialog on launch.

–testshell-startup-dialog

Causes the test shell process to display a dialog on launch.

–plugin-launcher

Specifies a command that should be used to launch the plugin process. Useful

for running the plugin process through purify or quantify. Ex:

–plugin-launcher=”path\to\purify /Run=yes.

–plugin-launche.

–channel

The value of this switch tells the child process which

IPC channel the browser expects to use to communicate with it.

–testing-channel

The value of this switch tells the app to listen for and broadcast

testing-related messages on IPC channel with the given ID.

–homepage

The value of this switch specifies which page will be displayed

in newly-opened tabs. We need this for testing purposes so

that the UI tests don't depend on what comes up for http://google.com.

–start-renderers-manually

When this switch is present, the browser will throw up a dialog box

asking the user to start a renderer process independently rather

than launching the renderer itself. (This is useful for debugging..

–renderer

Causes the process to run as renderer instead of as browser.

–renderer-path

Path to the executable to run for the renderer subproces.

–plugin

Causes the process to run as plugin hos.

–single-process

Runs the renderer and plugins in the same process as the browse.

–process-per-tab

Runs each set of script-connected tabs (i.e., a BrowsingInstance) in its own

renderer process. We default to using a renderer process for each

site instance (i.e., group of pages from the same registered domain with

script connections to each other).

–process-per-site

Runs a single process for each site (i.e., group of pages from the same

registered domain) the user visits. We default to using a renderer process

for each site instance (i.e., group of pages from the same registered

domain with script connections to each other).

–in-process-plugins

Runs plugins inside the renderer proces.

–no-sandbox

Runs the renderer outside the sandbox.

–safe-plugins

Runs the plugin processes inside the sandbox.

–trusted-plugins

Excludes these plugins from the plugin sandbox.

This is a comma separated list of plugin dlls name and activex clsid.

–test-sandbox

Runs the security test for the sandbox.

–user-data-dir

Specifies the user data directory, which is where the browser will look

for all of its state.

–app

Specifies that the associated value should be launched in “application” mode.

–upload-file

Specifies the file that should be uploaded to the provided application. This

switch is expected to be used with –app option.

–dom-automation

Specifies if the dom_automation_controller_ needs to be bound in the

renderer. This binding happens on per-frame basis and hence can potentially

be a performance bottleneck. One should only enable it when automating

dom based tests.

–plugin-path

Tells the plugin process the path of the plugin to loa.

–js-flags

Specifies the flags passed to JS engin.

–geoid

The GeoID we should use. This is normally obtained from the operating system

during first run and cached in the preferences afterwards. This is a numeric

value; see http://msdn.microsoft.com/en-us/library/ms776390.aspx .

–lang

The language file that we want to try to open. Of the form

language[-country] where language is the 2 letter code from ISO-639.

–debug-children

Will add kDebugOnStart to every child processes. If a value is passed, it

will be used as a filter to determine if the child process should have the

kDebugOnStart flag passed on or not.

–debug-on-start

Causes the process to start the JIT debugger on itself (mainly used by –debug-children.

–wait-for-debugger-children

Will add kWaitForDebugger to every child processes. If a value is passed, it

will be used as a filter to determine if the child process should have the

kWaitForDebugger flag passed on or not.

–wait-for-debugger

Waits for a debugger for 60 second.

–log-filter-prefix

Will filter log messages to show only the messages that are prefixed

with the specified valu.

–enable-logging

Force logging to be enabled. Logging is disabled by default in release

builds.

–dump-histograms-on-exit

Dump any accumualted histograms to the log when browser terminates (requires

logging to be enabled to really do anything). Used by developers and test

scripts.

–disable-logging

Force logging to be disabled. Logging is enabled by default in debug

builds.

–log-level

Sets the minimum log level. Valid values are from 0 to 3:

INFO = 0, WARNING = 1, LOG_ERROR = 2, LOG_FATAL = 3.

–remote-shell-port

Enable remote debug / automation shell on the specified por.

–uninstall

Runs un-installation steps that were done by chrome first-run.

–omnibox-popup-count

Number of entries to show in the omnibox popup.

–uninstallomnibox-popup-count

Removes the previous set suggestion coun.

–automation-channel

The value of this switch tells the app to listen for and broadcast

automation-related messages on IPC channel with the given ID.

–restore-last-session

Indicates the last session should be restored on startup. This overrides

the preferences value and is primarily intended for testing.

–record-mode

–playback-mode

Chrome supports a playback and record mode. Record mode saves *everything*

to the cache. Playback mode reads data exclusively from the cache. This

allows us to record a session into the cache and then replay it at will.

–no-events

Don't record/playback events when using record & playback.

–hide-icons

–show-icons

Make Windows happy by allowing it to show “Enable access to this program”

checkbox in Add/Remove Programs->Set Program Access and Defaults. This

only shows an error box because the only way to hide Chrome is by

uninstalling it.

–make-default-browser

Make Chrome default browse.

–proxy-server

Use a specified proxy server, overrides system settings. This switch only

affects HTTP and HTTPS requests.

–dns-log-details

–dns-prefetch-disable

Chrome will support prefetching of DNS information. Until this becomes

the default, we'll provide a command line switch.

–debug-print

Enables support to debug printing subsystem.

–allow-all-activex

Allow initialization of all activex controls. This is only to help website

developers test their controls to see if they are compatible in Chrome.

Note there's a duplicate value in activex_shared.cc (to avoid

dependency on chrome module). Please change both locations at the same time.

–disable-dev-tools

Browser flag to disable the web inspector for all renderers.

–always-enable-dev-tools

Enable web inspector for all windows, even if they're part of the browser.

Allows us to use our dev tools to debug browser windows itself.

–memory-model

Configure Chrome's memory model.

Does chrome really need multiple memory models? No. But we get a lot

of concerns from individuals about how the changes work on *their*

system, and we need to be able to experiment with a few choices.

–tab-count-to-load-on-session-restore

Used to set the value of SessionRestore::num_tabs_to_load_. See session_restore.h for details.

const wchar_t kTabCountToLoadOnSessionRestore[] .

–memory-profile

Enable dynamic loading of the Memory Profiler DLL, which will trace

all memory allocations during the run.

–enable-file-cookies

By default, cookies are not allowed on file://. They are needed in for

testing, for example page cycler and layout tests. See bug 1157243.

–start-maximized

Start the browser maximized, regardless of any previous settings.

TODO(pjohnson): Remove this once bug 1137420 is fixed. We are using this

as a workaround for not being able to use moveTo and resizeTo on a

top-level window.

–enable-watchdog

Spawn threads to watch for excessive delays in specified message loops.

User should set breakpoints on Alarm() to examine problematic thread.

Usage: -enable-watchdog=[ui][io]

Order of the listed sub-arguments does not matter.

–first-run

Display the First Run experience when the browser is started, regardless of

whether or not it's actually the first run.

–message-loop-strategy

–message-loop-histogrammer

Enable histograming of tasks served by MessageLoop. See about:histograms/Loop

for results, which show frequency of messages on each thread, including APC

count, object signalling count, etc.

–import

Perform importing from another browser. The value associated with this

setting encodes the target browser and what items to import.

–silent-dump-on-dcheck

Change the DCHECKS to dump memory and continue instead of crashing.

This is valid only in Release mode when –enable-dcheck is specified.

–disable-prompt-on-repost

Normally when the user attempts to navigate to a page that was the result of

a post we prompt to make sure they want to. This switch may be used to

disable that check. This switch is used during automated testing.

–disable-popup-blocking

Disable pop-up blocking.

–disable-javascript

Don't execute JavaScript (browser JS like the new tab page still runs).

–disable-java

Prevent Java from running.

–disable-plugins

Prevent plugins from running.

–disable-images

Prevent images from loading.

–use-lf-heap

Use the low fragmentation heap for the CRT.

–gears-plugin-path

Debug only switch to specify which gears plugin dll to load.

–gears-in-renderer

Switch to load Gears in the renderer process.

–enable-p13n

–javascript-debugger-path

Allow loading of the javascript debugger UI from the filesystem.

–new-http

Enable new HTTP stack.

到此這篇關(guān)于Selenium啟動(dòng)Chrome時(shí)配置選項(xiàng)詳解的文章就介紹到這了,更多相關(guān)Selenium啟動(dòng)Chrome內(nèi)容請(qǐng)搜索億速云以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持億速云!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI