How to add chromeoptions like selenium?
zhangsanfu opened this issue · 4 comments
zhangsanfu commented
how to add chromeoptions like selenium?
from selenium import webdriver
options = webdriver.ChromeOptions()
prefs = {
'profile.default_content_setting_values': {
'images': 2
}
}
options.add_experimental_option('prefs', prefs)
driver = webdriver.Chrome(chrome_options=options)
driver.get("http://www.google.com/")
#driver.quit()
boisei0 commented
I wrote a small patch for this a while ago, using it only on small projects and I haven't done enough testing yet for it to use in production, but I will soon and add a PR. Code is available here: boisei0@c049230
I'm using it for accessing the network tab to get specific headers out of XHR requests that are then passed forward when switching the session to Requests.
wtgg commented
I added 'extensions' and 'prefs' parameters into the function "_start_chrome_browser" in the "requestium.py" so that it can drive your chrome with .crx plugins or forbid images,notices.
See detail
try try this <( ̄ˇ ̄)> ↴
import platform
system = platform.system()
if system == 'Linux':
options = {
'binary_location': '/usr/bin/google-chrome',
'arguments': [
'--no-sandbox',
'disable-infobars',
# 'headless'
],
'extensions': [
'/opt/soft/XPathHelper.crx',
'/opt/soft/JsonHandle.crx',
'/opt/soft/有道词典Chrome划词插件.crx',
],
'prefs': {
# 不加载图片
# 'profile.managed_default_content_settings.images': 2,
# 禁止chrome页面通知
'profile.default_content_setting_values': {'notifications': 2}
}
}
if system == 'Windows':
options = {
'binary_location': 'C:/Users/Administrator/AppData/Local/Google/Chrome/Application/chrome.exe',
'arguments': [
'--no-sandbox',
'disable-infobars',
'headless'
],
'extensions': [
'D:/soft/XPathHelper.crx',
'D:/soft/soft/JsonHandle.crx'
],
'prefs': {
# 不加载图片
'profile.managed_default_content_settings.images': 2,
# 禁止chrome页面通知
'profile.default_content_setting_values': {'notifications': 2}
},
}
webdriver_path = r'/opt/soft/chromedriver' if system == 'Linux' else r'D:/soft/chromedriver.exe'
s = Session(
webdriver_path=webdriver_path,
browser='chrome',
default_timeout=5,
webdriver_options=options
)
driver = s.driver
driver.get('https://www.baidu.com/')
gordianbahri commented
How would I add:
options.add_experimental_option...
?