Selenium下Chrome配置 (含启动无痕界面--无界面浏览器)

例子: 设置无界面模式浏览器启动
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--headless')
driver = webdriver.Chrome(chrome_options=chrome_options)

地址:https://peter.sh/experiments/chromium-command-line-switches/

chrome_options.add_argument('--headless') # 无头模式
chrome_options.add_argument('--disable-gpu') # 禁用GPU加速
chrome_options.add_argument('--start-maximized')#浏览器最大化
chrome_options.add_argument('--window-size=1280x1024') # 设置浏览器分辨率(窗口大小)
chrome_options.add_argument('log-level=3')
#info(default) = 0
#warning = 1
#LOG_ERROR = 2
#LOG_FATAL = 3

chrome_options.add_argument('--user-agent=""') # 设置请求头的User-Agent
chrome_options.add_argument('--disable-infobars') # 禁用浏览器正在被自动化程序控制的提示
chrome_options.add_argument('--incognito') # 隐身模式(无痕模式)
chrome_options.add_argument('--hide-scrollbars') # 隐藏滚动条, 应对一些特殊页面
chrome_options.add_argument('--disable-javascript') # 禁用javascript
chrome_options.add_argument('--blink-settings=imagesEnabled=false') # 不加载图片, 提升速度

chrome_options.add_argument('--ignore-certificate-errors') # 禁用扩展插件并实现窗口最大化
chrome_options.add_argument('–disable-software-rasterizer')
chrome_options.add_argument('--disable-extensions')

 

from selenium import webdriver

# 进入浏览器设置
options = webdriver.ChromeOptions()
# 设置中文
options.add_argument('lang=zh_CN.UTF-8')
# 更换头部
options.add_argument('user-agent="Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit/603.1.3 (KHTML, like Gecko) Version/10.0 Mobile/14E304 Safari/602.1 wechatdevtools/1.02.1911180 MicroMessenger/7.0.4 Language/zh_CN webview/16088272312572834 webdebugger port/46641","Accept":"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;"')
options.add_argument('Accept:"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3"')
options.add_argument('Cookie:"staging-authorization=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoxMjc2MjA0OCwidXNlcl90eXBlIjoic3R1ZGVudCIsImp0aSI6ImVhZDUyOGUzLTc0M2MtNDc5NC1iNWJmLTM0NWVkOTJhNmFhZSIsImlhdCI6MTYwODczMDM5Mn0.vfnp6yyoAvDvC_Ut4TV-yAdc6n_L9iSdjNsHvnhb_Og; staging-refresh-token=MToxMjc2MjA0ODp3ZWI6QUFBQmRvX050MW5YOHlqTkRoSDNMNWY4SGdMSHRLcTc6ODZmOTk5MWQtYWJlYy00NDIxLWE3OWItYzI3NzNiYmUwNWZk; __ca_uid_key__=fa8f0604-1ac3-4d4d-b113-816d1aac1ba4; authorization=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoxNDIyNjk2NiwidXNlcl90eXBlIjoic3R1ZGVudCIsImp0aSI6IjU2NjdhMDAxLTZhNjEtNGRlYi04MmE5LTQ1Y2QyMGZjYjUwYSIsImlhdCI6MTYwODczNzI3MH0.ng3Cad-bgtampqTEcai21CtLXb53b9D8c7cPsYmBLq8; refresh-token=MToxNDIyNjk2Njp3ZWI6QUFBQmRwQTJxMlY3SXVCX2ZKVkYzdmtKN3VZZXhpS086ZTMzZDMwZTQtZDljYy00Nzc2LTkyYjMtM2YzOWQxYzg1MjU5"')
options.add_argument('options.add_argument:"eyJraWQiOiIyMmZhZjZiNi1lYmMxLTQyMWMtOWJmNS1hNGZhMjQ4NzEwMWQiLCJ0eXAiOiJKV1QiLCJhbGciOiJSUzUxMiJ9.eyJhdGhfY2lkIjoid2ViIiwic3ViIjoiQ29kZW1hbyBBdXRoIiwiYXRoX3VpZCI6IjEwMDA1ODUyMzkiLCJhdGhfdHlwIjoxLCJpc3MiOiJBdXRoIFNlcnZpY2UiLCJhdGhfdmVyIjoiMS4wLjAiLCJleHAiOjE2MDkzMzk1NDUsImlhdCI6MTYwOTMzMjM0NSwianRpIjoiQUFBQmRyT3V5MTFIU1NzUW5tTFZTMUhsMUFXbmJJWF8ifQ.RnGY0I8OZPJ9PopJJGCLy4dwn-SlWS2Rn90s6XjK6n6iUqNajtCmMjeXBjX86Qt0de-VkokK4J8qyM7oGdhAJ25VpczirtJrnHK4Iwgw3IXoQbQamt6I6jRpFOLKgcd38n-DhU7Cq37dLWzjx148reeMzBRYGMoEcl1Q4Ewobjo_PBcURNJmITngvocPIylt4gPves9-R1eerLiSM5i2FAJ2WiUM29y2hGTmQBkR0D7XwUElC7OzT274uMFYM-JWr21Z5hvuwMPEKMy_Ty2wrzj-EFRyL1ODNCWQUTcA6cstSLNNFg2pXUAur7tv_9Vk_Kf0l5gUxk7NQqNOU5Nq9Q"')
browser = webdriver.Chrome(chrome_options=options, executable_path= r'/Users/lucax/Downloads/chromedriver 2')
url = 'https://staging-exodus.codemao.cn/h5/b2c?id=166&landingType=2'
browser.get(url)
# browser.quit()

 

posted @ 2019-08-30 00:56  凯宾斯基  阅读(8913)  评论(0编辑  收藏  举报