Cei*_*ing 7 css python selenium google-chrome selenium-chromedriver
我尝试显示没有CSS的页面以加快加载速度,并且我已设法使用以下代码禁用图像和javascript:
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)
Run Code Online (Sandbox Code Playgroud)
于是,我换{'profile.default_content_setting_values': {'images': 2, 'javascript': 2}}到{'profile.default_content_setting_values': {'css': 2},并认为这将禁用CSS,但没有奏效.
我已经看到很多Firefox的答案,现在我想在Chrome中这样做.
要显示没有CSS的页面,为了使页面加载更快,您可以禁用首选项使用以下解决方案
代码块:
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')
Run Code Online (Sandbox Code Playgroud)浏览器快照:
不幸的是,这在 Chrome 中是不可能的。
如果没有像 Xserver 这样的虚拟屏幕,Chrome/chromedriver 就无法无头运行,并且它无法不渲染html 和 css。
允许的所有选项的详尽列表:
profile.default_content_setting_values:
cookies,
images,
javascript,
plugins,
popups,
geolocation,
notifications,
auto_select_certificate,
fullscreen,
mouselock,
mixed_script,
media_stream,
media_stream_mic,
media_stream_camera,
protocol_handlers,
ppapi_broker,
automatic_downloads,
midi_sysex,
push_messaging,
ssl_cert_decisions,
metro_switch_to_desktop,
protected_media_identifier,
app_banner,
site_engagement,
durable_storage
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3202 次 |
| 最近记录: |