Selenium启动Chrome时配置选项详解

Selenium操作浏览器是不加载任何配置的,网上找了半天,关于Firefox加载配置的多点,Chrome资料很少,下面是关于加载Chrome配置的方法:

一、加载所有Chrome配置

用Chrome地址栏输入chrome://version/,查看自己的“个人资料路径”,然后在浏览器启动时,调用这个配置文件,代码如下:

#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') #设置成用户自己的数据目录
driver = webdriver.Chrome(chrome_options=option)

二、修改浏览器的User-Agent来伪装你的浏览器访问手机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/')

三、浏览器启动时安装crx扩展

#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的地址栏命令(这些命令会不停的变动,所有不一定都是好用的)

在Chrome的浏览器地址栏中输入以下命令,就会返回相应的结果。这些命令包括查看内存状态,浏览器状态,网络状态,DNS服务器状态,插件缓存等等。
  about:version - 显示当前版本
  about:memory - 显示本机浏览器内存使用状况
  about:plugins - 显示已安装插件
  about:histograms - 显示历史记录
  about:dns - 显示DNS状态
  about:cache - 显示缓存页面
  about:gpu -是否有硬件加速
  about:flags -开启一些插件 //使用后弹出这么些东西:“请小心,这些实验可能有风险”,不知会不会搞乱俺的配置啊!
  chrome://extensions/ - 查看已经安装的扩展
  其他的一些关于Chrome的实用参数及简要的中文说明(使用方法同上,当然也可以在shell中使用)
  –user-data-dir=”[PATH]” 指定用户文件夹User Data路径,可以把书签这样的用户数据保存在系统分区以外的分区。
  –disk-cache-dir=”[PATH]“ 指定缓存Cache路径
  –disk-cache-size= 指定Cache大小,单位Byte
  –first run 重置到初始状态,第一次运行
  –incognito 隐身模式启动
  –disable-javascript 禁用Javascript
  --omnibox-popup-count="num" 将地址栏弹出的提示菜单数量改为num个。我都改为15个了。
  --user-agent="xxxxxxxx" 修改HTTP请求头部的Agent字符串,可以通过about:version页面查看修改效果
  --disable-plugins 禁止加载所有插件,可以增加速度。可以通过about:plugins页面查看效果
  --disable-javascript 禁用JavaScript,如果觉得速度慢在加上这个
  --disable-java 禁用java
  --start-maximized 启动就最大化
  --no-sandbox 取消沙盒模式
  --single-process 单进程运行
  --process-per-tab 每个标签使用单独进程
  --process-per-site 每个站点使用单独进程
  --in-process-plugins 插件不启用单独进程
  --disable-popup-blocking 禁用弹出拦截
  --disable-plugins 禁用插件
  --disable-images 禁用图像
  --incognito 启动进入隐身模式
  --enable-udd-profiles 启用账户切换菜单
  --proxy-pac-url 使用pac代理 [via 1/2]
  --lang=zh-CN 设置语言为简体中文
  --disk-cache-dir 自定义缓存目录
  --disk-cache-size 自定义缓存最大值(单位byte)
  --media-cache-size 自定义多媒体缓存最大值(单位byte)
  --bookmark-menu 在工具 栏增加一个书签按钮
  --enable-sync 启用书签同步

常用:

–single-process 单进程运行Google Chrome

–start-maximized 启动Google Chrome就最大化

–disable-java 禁止Java

–no-sandbox  非沙盒模式运行

全部:(下面的没有进行翻译,仔细看下应该都看得懂. ~ ~)

–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.

到此这篇关于Selenium启动Chrome时配置选项详解的文章就介绍到这了,更多相关Selenium启动Chrome内容请搜索我们以前的文章或继续浏览下面的相关文章希望大家以后多多支持我们!

(0)

相关推荐

  • selenium + ChromeDriver安装及使用方法

    Selenium是一个用于Web应用程序测试的工具.Selenium测试直接运行在浏览器中,就像真正的用户在操作一样.而对于爬虫来说,使用Selenium操控浏览器来爬取网上的数据那么肯定是爬虫中的杀手武器.这里,我将介绍selenium + 谷歌浏览器的一般使用.首先会介绍如何安装部署环境,然后贴出一些本人所使用的一些方法,最后给出github地址,供大家下载. 1. selenium 环境配置 selenium 官网地址:http://www.seleniumhq.org/download/

  • 详解mac python+selenium+Chrome 简单案例

    第一步:下载selenium pip install selenium 第二步:下载和你当前谷歌浏览器对应的驱动Chromedriver 下载地址:https://npm.taobao.org/mirrors/chromedriver 这是我谷歌对应的版本,点击选择下载对应的系统文件,下载完解压到你项目的目录里即可! 第三步:简单操作selenium from selenium import webdriver import time # 创建Chrome的驱动对象 driver = webdr

  • Selenium chrome配置代理Python版的方法

    环境: windows 7 + Python 3.5.2 + Selenium 3.4.2 + Chrome Driver 2.29 + Chrome 58.0.3029.110 (64-bit) Selenium官方给的Firefox代理配置方式并不起效,也没看到合适的配置方式,对于Chrome Selenium官方没有告知如何配置,但以下两种方式是有效的: 1. 连接无用户名密码认证的代理 chromeOptions = webdriver.ChromeOptions() chromeOpt

  • python selenium 执行完毕关闭chromedriver进程示例

    因为使用多次以后发现进程中出现了很多chromedriver的残留,造成卡顿,所以决定优化一下. 这个问题困扰了楼主很久,百度谷歌查来查去都只有java,后面根据java和selenium结合看找出了python如何执行完把chromedriver进程关闭 Python的话控制chromedriver的开启和关闭的包是Service from selenium.webdriver.chrome.service import Service 创建的时候需要把chromedriver.exe的位置写

  • 使用selenium自动控制浏览器找不到Chromedriver问题

    ChromeDriver 是 google 为网站开发人员提供的自动化测试接口,它是 selenium2 和 chrome浏览器 进行通信的桥梁.selenium 通过一套协议(JsonWireProtocol :https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol)和 ChromeDriver 进行通信,selenium 实质上是对这套协议的底层封装,同时提供外部 WebDriver 的上层调用类库. 下面看下解决使用sele

  • selenium+java+chrome环境搭建的方法步骤

    我只能说因为版本冲突,简直太折腾了,而搜了无数个博友的帖子才找到正确条案,就不能好好的写篇文章吗? 最近真的是太闲太闲了,平时没事总得搞点技术,不然心里感觉好空虚, 最近看上了selenium,所以试一下 没啥目标 头一篇这个环境搞的崩溃了,都是版本冲突,目前为止,我还未有解决firefox与selenium的版本冲突问题 这是一篇只讲chrome的文章 1.selenium下载最新版本,我在官网下载的 http://selenium-release.storage.googleapis.com

  • python+selenium+Chrome options参数的使用

    Chrome Options常用的行为一般有以下几种: 禁止图片和视频的加载:提升网页加载速度. 添加代理:用于翻墙访问某些页面,或者应对IP访问频率限制的反爬技术. 使用移动头:访问移动端的站点,一般这种站点的反爬技术比较薄弱. 添加扩展:像正常使用浏览器一样的功能. 设置编码:应对中文站,防止乱码. 阻止JavaScript执行 ... Chrome Options是一个配置chrome启动时属性的类,通过这个参数我们可以为Chrome添加如下参数: 设置 chrome 二进制文件位置 (b

  • Python使用selenium + headless chrome获取网页内容的方法示例

    使用python写爬虫时,优选selenium,由于PhantomJS因内部原因已经停止更新,最新版的selenium已经使用headless chrome替换掉了PhantomJS,所以建议将selenium更新到最新版,使用selenium + headless chrome 准备工作: 安装chrome.chrome driver.selenium 一.安装chrome 配置yum下载源,在目录/etc/yum.repos.d/下新建文件google-chrome.repo > cd /e

  • Python3+Selenium+Chrome实现自动填写WPS表单

    引言   本文通过python3.第三方python库Selenium和谷歌浏览器Chrome,完成WPS表单的自动填写. 开发环境配置   python3的安装:略,网上都有教程.   Selenium的安装:在命令行输入pip3 install selenium并回车即可完成安装,如果不成功,查找网上教程.   Chrome的安装:略,网上都有教程.   因为Selenium需要ChromeDriver来驱动Chrome,所以还需要下载驱动ChromeDriver.下面重点介绍一下Chrom

  • Selenium启动Chrome时配置选项详解

    Selenium操作浏览器是不加载任何配置的,网上找了半天,关于Firefox加载配置的多点,Chrome资料很少,下面是关于加载Chrome配置的方法: 一.加载所有Chrome配置 用Chrome地址栏输入chrome://version/,查看自己的"个人资料路径",然后在浏览器启动时,调用这个配置文件,代码如下: #coding=utf-8 from selenium import webdriver option = webdriver.ChromeOptions() opt

  • Activity配置、启动和关闭activity实例详解

    大家先看下效果图: Android为我们提供了四种应组件,分别为Activity.Service.Broadcast receivers和Content providers,这些组建也就是我们开发一个Android应用程序的基石.系统可以通过不同组建提供的切入点进入到开发的应用程序中.对用户来说不是所有的组建都是实际的切入点,但是他们之间都是相互依赖的,它们每一个作为存在的实体,扮演着特定的角色,作为独一无二的基石帮助开发者定义Android应用的行为.下面我将整理自己的Activity学习点滴

  • selenium+python环境配置教程详解

    一.安装Python 1)官网下载安装 2)配置环境变量(未勾选自动配置需要手动配置) 3)检查是否安装成功(交互窗口中输入Python -v) 二.Selenium 3.X +FireFox 驱动 +geckodriver 1.安装selenium: 1)W+r输入cmd,然后输入pip install selenium 2)安装FireFox,添加附加组件selenium IDE.FireBUG 3) https://github.com/mozilla/geckodriver/releas

  • vue项目中企业微信使用js-sdk时config和agentConfig配置方式详解

    1.如果只使用config配置的相关js接口 可采用如下方式引入 执行 npm weixin-sdk-js --save 局部引入 在vue页面中 import wx from 'weixin-sdk-js'; 全局引入 在vue 的main.js 页面中 引入后编写到vue原型链上,然后全局调用 import wx from "weixin-sdk-js"; Vue.prototype.$wx = wx; 2.如果要使用agentConfig配置的相关接口 一定不要执行npm命令引入

  • Admin - SpringBoot + Maven 多启动环境配置实例详解

    一:父级pom.xml文件 resources目录下新建指定文件夹,存放Spring配置文件 <profiles> <profile> <id>dev</id> <properties> <profiles.active>dev</profiles.active> </properties> <activation> <activeByDefault>true</activeByD

  • Redis Sentinel服务配置流程(详解)

    1.Redis Sentinel服务配置 1.1简介 Redis 的 Sentinel 系统用于管理多个 Redis 服务器(instance), 该系统执行以下三个任务: 监控(Monitoring): Sentinel 会不断地检查你的主服务器和从服务器是否运作正常. 提醒(Notification): 当被监控的某个 Redis 服务器出现问题时, Sentinel 可以通过API 向管理员或者其他应用程序发送通知. 自动故障迁移(Automatic failover): 当一个主服务器不

  • php.ini中的php-5.2.0配置指令详解

    ;; 关于php.ini ;;  这个文件必须命名为'php.ini'并放置在httpd.conf中的PHPIniDir指令指定的目录中. ; 最新版本的php.ini可以在下面两个位置查看: ; http://cvs.php.net/viewvc.cgi/php-src/php.ini-recommended?view=co ; http://cvs.php.net/viewvc.cgi/php-src/php.ini-dist?view=co ;;;;;;;;;;;; ;; 语法 ;; ;;

  • MongoDB4.0在windows10下的安装与服务配置教程详解

    本地安装及网页测试 1.在官网下载最新的安装文件 下载地址 : https://www.mongodb.com/download-center#community 可以在MongoDB官网选择Community Server版本下载,但是它似乎经常没有响应.可以在这里直接选择需要的版本下载,要在Windows下安装可以直接选msi安装文件. 安装msi文件 下载好后,一致next,在中间一步选择 custom 选项,以选定自己喜好的安装位置 修改安装路径. 这个MSI文件有问题,这里必须不能改动

  • Docker守护进程安全配置项目详解

    本文将为大家介绍docker守护进程的相关安全配置项目. 一.测试环境 1.1 安装 CentOS 7 CentOS Linux release 7.7.1908 (Core) 升级内核,重启 # yum update kernel [root@localhost docker]# uname -a Linux localhost 3.10.0-1062.12.1.el7.x86_64 #1 SMP Tue Feb 4 23:02:59 UTC 2020 x86_64 x86_64 x86_64

  • Intellij IDEA 2020.3 配置教程详解

    设置项 这个版本已经取消了defalut settings指定成默认配置的选项,所以配置都是在settings中配置 设置项 设置统一UTF-8编码 路径:File -> settings --> editor --> File Encodings 勾选Transparent native-to-ascii conversion : 解决比如properties 文件中的unicode乱码 设置默认JDK 路径:File-> Project Structure 设置平台的SDKs

随机推荐