python中options设置_如何使用ChromeOptions在Python硒中禁用CSS

I try to show the page without CSS to make loading faster, and I have managed to disable images and javascript using the following code:

option = webdriver.ChromeOptions()

prefs = {'profile.default_content_setting_values': {'images': 2, 'javascript': 2}}

option.add_experimental_option('prefs', prefs)

driver = webdriver.Chrome(chrome_options = option)

So, I changed{'profile.default_content_setting_values': {'images': 2, 'javascript': 2}}to {'profile.default_content_setting_values': {'css': 2}, and thought it would disable CSS, but it didn't work.

I have seen many answers for Firefox, now I want to do this in Chrome.

解决方案

To show the page without CSS, to make page loading faster you can disable the Preferences used for storing the default values for the individual content settings using the following solution:

Code Block:

from selenium import webdriver

options = webdriver.ChromeOptions()

prefs = {'profile.default_content_setting_values': {'cookies': 2, 'images': 2, 'javascript': 2,

'plugins': 2, 'popups': 2, 'geolocation': 2,

'notifications': 2, 'auto_select_certificate': 2, 'fullscreen': 2,

'mouselock': 2, 'mixed_script': 2, 'media_stream': 2,

'media_stream_mic': 2, 'media_stream_camera': 2, 'protocol_handlers': 2,

'ppapi_broker': 2, 'automatic_downloads': 2, 'midi_sysex': 2,

'push_messaging': 2, 'ssl_cert_decisions': 2, 'metro_switch_to_desktop': 2,

'protected_media_identifier': 2, 'app_banner': 2, 'site_engagement': 2,

'durable_storage': 2}}

options.add_experimental_option('prefs', prefs)

options.add_argument("start-maximized")

options.add_argument("disable-infobars")

options.add_argument("--disable-extensions")

driver = webdriver.Chrome(chrome_options=options, executable_path=r'C:\Utility\BrowserDrivers\chromedriver.exe')

driver.get('https://play.google.com/store')

Browser Snapshot:

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值