首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何使用ChromeOptions禁用Python中的CSS

如何使用ChromeOptions禁用Python中的CSS
EN

Stack Overflow用户
提问于 2018-02-28 14:06:25
回答 3查看 13.8K关注 0票数 15

我试图在没有CSS的情况下显示页面,以使加载速度更快,并且我已经使用以下代码禁用了图像和javascript:

代码语言: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)

因此,我将{'profile.default_content_setting_values': {'images': 2, 'javascript': 2}}更改为{'profile.default_content_setting_values': {'css': 2},并认为它会禁用CSS,但它没有工作。

我已经看到了火狐的许多答案,现在我想在Chrome上这样做。

EN

回答 3

Stack Overflow用户

发布于 2018-11-26 12:23:50

要显示没有CSS的页面,要使页面加载更快,可以使用以下解决方案禁用用于存储单个内容设置默认值的首选项

  • 代码块: 从selenium导入webdriver.ChromeOptions= webdriver.ChromeOptions() prefs ={‘profile.default_content_select_value’:{‘cookie’:2,‘图像’:2,'javascript':2,'plugins':2,‘弹出窗口’:2,‘地理定位’:2,‘通知’:2,‘auto_select_证书’:2,‘全屏’:2,“‘mouselock”:2,“混合脚本”:2,“media_stream”:2,“media_stream_midi”:2,“media_stream_camera”:2,“protocol_handlers”:2,“ppapi_broker”:2,“automatic_midi”:2,“midi_sysex”:2,‘'push_messaging':2,'ssl_cert_decisions':2,’metro_switch_to_桌面‘:2,’受保护_媒体_标识符‘:2,'app_banner':2,’site_storage‘:2,’耐久_存储‘:2}} options.add_experimental_option('prefs',Options.add_argument(“启动-最大化”)options.add_argument(“禁用-infobars”)options.add_argument(“-禁用-扩展”)驱动= webdriver.Chrome(chrome_options=options,chrome_options=options driver.get('https://play.google.com/store') )
  • 浏览器快照:

票数 5
EN

Stack Overflow用户

发布于 2018-09-13 11:21:27

不幸的是,这是不可能在Chrome。

ChromeDriver禁用呈现和CSS

没有Xserver这样的虚拟屏幕,Chrome/chromedriver就不能无头运行,它也不能将呈现为html和css。

所允许的所有备选方案的详尽清单:

profile.default_content_setting_values:

代码语言:javascript
运行
复制
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
票数 3
EN

Stack Overflow用户

发布于 2022-04-08 16:43:33

我一直在想同样的事情,并发现了这一点(归功于https://www.scrapehero.com/how-to-increase-web-scraping-speed-using-puppeteer/)

这不是selenium,但在Pyppeteer中,您可以使用setRequestInterception拦截和修改页面发出的网络请求。这将允许您拦截和中止css网络请求,这将避免下载css文件及其后续呈现。

相关电子版文档

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49031428

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档