Python:在 Selenium Google ChromeDriver 中禁用图像 [英] Python: Disable images in Selenium Google ChromeDriver
问题描述
我花了很多时间来搜索这个.在一天结束时,我结合了一些答案并且它有效.我分享我的答案,如果有人编辑它或为我们提供更简单的方法来做到这一点,我将不胜感激.
I spend a lot of time searching about this. At the end of the day I combined a number of answers and it works. I share my answer and I'll appreciate it if anyone edits it or provides us with an easier way to do this.
1- 禁用 Selenium Google ChromeDriver 中的图像 中的答案适用于爪哇.所以我们应该在 Python 中做同样的事情:
1- The answer in Disable images in Selenium Google ChromeDriver works in Java. So we should do the same thing in Python:
opt = webdriver.ChromeOptions()
opt.add_extension("Block-image_v1.1.crx")
browser = webdriver.Chrome(chrome_options=opt)
2- 但是下载Block-image_v1.1.crx"有点棘手,因为没有直接的方法可以做到这一点.为此,而不是去:https://chrome.google.com/网上商店/详细信息/块图像/pehaalcefcjfccdpbckoablngfkfgfgj
2- But downloading "Block-image_v1.1.crx" is a little bit tricky, because there is no direct way to do that. For this purpose, instead of going to: https://chrome.google.com/webstore/detail/block-image/pehaalcefcjfccdpbckoablngfkfgfgj
你可以去http://chrome-extension-downloader.com/并将扩展程序 url 粘贴到那里,以便能够下载扩展文件.
you can go to http://chrome-extension-downloader.com/ and paste the extension url there to be able to download the extension file.
3- 然后你就可以使用上面提到的代码和你下载的扩展文件的路径了.
3- Then you will be able to use the above mentioned code with the path to the extension file that you have downloaded.
推荐答案
这是禁用图像的另一种方法:
Here is another way to disable images:
from selenium import webdriver
chrome_options = webdriver.ChromeOptions()
prefs = {"profile.managed_default_content_settings.images": 2}
chrome_options.add_experimental_option("prefs", prefs)
driver = webdriver.Chrome(chrome_options=chrome_options)
我在下面找到了:
这篇关于Python:在 Selenium Google ChromeDriver 中禁用图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!