selenium 定制启动chrome的参数

selenium 定制启动chrome的参数
设置代理. 禁止图片加载 修改ua
https://blog.csdn.net/vinson0526/article/details/51850929

1.配置chrome以手机模拟器
https://blog.csdn.net/u013948858/article/details/81123951

from selenium import webdriver
 
mobile_emulation = { "deviceName": "Nexus 5" }
 
chrome_options = webdriver.ChromeOptions()
 
chrome_options.add_experimental_option("mobileEmulation", mobile_emulation) # 这里看清楚了,不是add_argument
 
driver = webdriver.Remote(command_executor='http://127.0.0.1:4444/wd/hub',desired_capabilities = chrome_options.to_capabilities())

#====
from selenium import webdriver
 
from selenium.webdriver.chrome.options import Options
 
mobile_emulation = {
 
   "deviceMetrics": { "width": 360, "height": 640, "pixelRatio": 3.0 },
 
   "userAgent": "Mozilla/5.0 (Linux; Android 4.2.1; en-us; Nexus 5 Build/JOP40D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19" }
 
chrome_options = Options()
 
chrome_options.add_experimental_option("mobileEmulation", mobile_emulation) # 这里看清楚了,不是add_argument
 
driver = webdriver.Chrome(chrome_options = chrome_options) # 这里的chrome_options 建议都使用 desired_capabilities ,应为在Grid分布式中比较方便
 

2.取消显示 收到自动化软件的控制 / 静默方式运行

from selenium import webdriver

# 加启动配置
option = webdriver.ChromeOptions()
option.add_argument('disable-infobars')
#return webdriver.Chrome(chrome_options = option,desired_capabilities = None)

# 打开chrome浏览器
driver = webdriver.Chrome(chrome_options=option)
driver.get("https://www.baidu.com") 

from selenium import webdriver

# 加启动配置
option = webdriver.ChromeOptions()
option.add_argument('headless')

# 打开chrome浏览器
driver = webdriver.Chrome(chrome_options=option)
driver.get("https://www.baidu.com")
posted @ 2019-06-04 16:45  lvusyy  阅读(1064)  评论(0编辑  收藏  举报