options.add_argument(r'--user-data-dir=C:\Users\name\AppData\Local\Google\Chrome\User Data') 绕过登录

chrome配置
转自: https://www.jianshu.com/p/5669fa439c2b
–ignore-certificate-errors
–allow-running-insecure-content

启动参数:
–User-data-dir=“UserData”
设置用户目录;
–disk-cache-dir="%Temp%\Chrome"
设置缓存目录;
–enable-extensions
启动用户扩展;
–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)

'''#模仿手机
    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')
# 设置下载路径
chromeOptions = webdriver.ChromeOptions()
prefs = {"download.default_directory": "/path/download"}
chromeOptions.add_experimental_option("prefs", prefs)
driver = webdriver.Chrome(executable_path=chromedriver, chrome_options=chromeOptions)
# 设置代理
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")#设置为 headless 模式
options.add_argument("–window-size=100,100")#设置窗口大小
options.add_experimental_option(‘mobileEmulation’, mobileEmulation)

driver = webdriver.Chrome(chrome_options=options)

driver.get(‘http://m.baidu.com’)

sleep(3)

driver.close()

####模仿手机####

-- 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)

注意引号后有空格

options.add_argument("–lang=" + “zh-CN”)
#切换浏览器语言

options.add_argument("–test-type", “–ignore-certificate-errors”)
#忽略 Chrome 浏览器证书错误报警提示

DesiredCapabilities capabilities = DesiredCapabilities.chrome()
capabilities.setCapability(“chrome.switches”, Arrays.asList("–start-maximized"))
options.addArguments("–test-type", “–start-maximized”,“no-default-browser-check”)
#意思好像是测试模式,最大化浏览器并且默认不检查浏览器

options.addExtensions(new File(“C:\Users\username\AppData\Local\Google\Chrome\UserData\Default\Extensions\ijaobnmmgonppmablhldddpfmgpklbfh\1.6.0_0.crx”))
#添加扩展的方法,将crx文件所在的路径添加进去

序号 参数 说明
1 --allow-outdated-plugins 不停用过期的插件。
2 --allow-running-insecure-content 默认情况下,https 页面不允许从 http 链接引用 javascript/css/plug-ins。添加这一参数会放行这些内容。
3 --allow-scripting-gallery 允许拓展脚本在官方应用中心生效。默认情况下,出于安全因素考虑这些脚本都会被阻止。
4 --disable-accelerated-video 停用 GPU 加速视频。
5 --disable-dart 停用 Dart。
6 --disable-desktop-notifications 禁用桌面通知,在 Windows 中桌面通知默认是启用的。
7 --disable-extensions 禁用拓展。
8 --disable-file-system 停用 FileSystem API。
9 --disable-preconnect 停用 TCP/IP 预连接。
10 --disable-remote-fonts 关闭远程字体支持。SVG 中字体不受此参数影响。
11 --disable-speech-input 停用语音输入。
12 --disable-web-security 不遵守同源策略。
13 --disk-cache-dir 将缓存设置在给定的路径。
14 --disk-cache-size 设置缓存大小上限,以字节为单位。
15 --dns-prefetch-disable 停用DNS预读。
16 --enable-print-preview 启用打印预览。
17 --extensions-update-frequency 设定拓展自动更新频率,以秒为单位。
18 --incognito 让浏览器直接以隐身模式启动。
19 --keep-alive-for-test 最后一个标签关闭后仍保持浏览器进程。(某种意义上可以提高热启动速度,不过你最好得有充足的内存)
20 --kiosk 启用kiosk模式。(一种类似于全屏的浏览模式)
21 --lang 使用指定的语言。
22 --no-displaying-insecure-content 默认情况下,https 页面允许从 http 链接引用图片/字体/框架。添加这一参数会阻止这些内容。
23 --no-first-run 跳过 Chromium 首次运行检查。
24 --no-referrers 不发送 Http-Referer 头。
25 --no-sandbox 彻底停用沙箱。
26 --no-startup-window 启动时不建立窗口。
27 --proxy-pac-url 使用给定 URL 的 pac 代理脚本。(也可以使用本地文件,如 --proxy-pac-url=“file:\\c:\proxy.pac”)
28 --proxy-server 使用给定的代理服务器,这个参数只对 http 和 https 有效。(例如 --proxy-server=127.0.0.1:8087 )
29 --single-process 以单进程模式运行 Chromium。(启动时浏览器会给出不安全警告)
30 --start-maximized 启动时最大化。
31 --user-agent 使用给定的 User-Agent 字符串

参数:–user-data-dir=UserDataDir
用途:自订使用者帐户资料夹(如:–user-data-dir=“D:\temp\Chrome User Data”)
参数:–process-per-tab
用途:每个分页使用单独进程
参数:–process-per-site
用途:每个站点使用单独进程
参数:–in-process-plugins
用途:插件不启用单独进程

参数:–disable-popup-blocking
用途:禁用弹出拦截
参数:–disable-javascript
用途:禁用JavaScript
参数:–disable-java
用途:禁用Java
参数:–disable-plugins
用途:禁用插件
参数:–disable-images
用途:禁用图像
参数:–omnibox-popup-count=”num”
用途:将网址列弹出的提示选单数量改为num个
参数:–enable-vertical-tabs
用途:调整chrome游览器标签存放在左边,非顶部

嗯chrome配置就酱紫了
觉得奇怪总是能打开chrome但是不能打开网页
报错如下:

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)

明明是对的版本==明明我js执行测试脚本时都能打开chrome思考ing
59配29的driver
Extension Automation 能够监视网页地址自动启用或禁用扩展
Paste_Image.png
Paste_Image.png
来源:

http://blog.lihaixin.name/2010/08/chrome-command-line-parameter.html
http://code.google.com/p/xiaody/wiki/ChromiumCommandLineSwitches
http://tieba.baidu.com/p/685173694

  • 4
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值