Python:在Selenium Google ChromeDriver中禁用图片 [英] Python: Disable images in Selenium Google ChromeDriver

查看:1071
本文介绍了Python:在Selenium Google ChromeDriver中禁用图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我花了很多时间来研究这个问题。
在一天结束时,我结合了许多答案,并且它可以工作。我分享我的答案,如果有人编辑它或为我们提供更简单的方法,我会很感激。

1-答案在 Selenium中的不可用图像Google ChromeDriver 适用于Java。所以我们应该在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/ webstore / detail / block-image / pehaalcefcjfccdpbckoablngfkfgfgj

你可以到 http://chrome-extension-downloader.com/
并粘贴扩展名网址,以便能够下载扩展文件。



3-然后您就可以使用上面提到的代码和您下载的扩展文件的路径。 / DIV>

感谢。
这是禁用图片的另一种方式,

  chromeOptions = webdriver.ChromeOptions()
prefs = { profile.managed_default_content_settings.images:2}
chromeOptions.add_experimental_option(prefs,prefs)
driver = webdriver.Chrome(chrome_options = chromeOptions)

我在下面找到它:

http://nullege.com/codes/show/src@o@s@osintstalker-HEAD @ fbstalker1.py / 56 / selenium.webdriver.ChromeOptions.add_experimental_option


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- 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- 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

you can go to http://chrome-extension-downloader.com/ and paste the extension url there to be able to download the extension file.

3- Then you will be able to use the above mentioned code with the path to the extension file that you have downloaded.

解决方案

Thanks. Here is another way to disable images,

chromeOptions = webdriver.ChromeOptions()
prefs = {"profile.managed_default_content_settings.images":2}
chromeOptions.add_experimental_option("prefs",prefs)
driver = webdriver.Chrome(chrome_options=chromeOptions)

I found it below:

http://nullege.com/codes/show/src@o@s@osintstalker-HEAD@fbstalker1.py/56/selenium.webdriver.ChromeOptions.add_experimental_option

这篇关于Python:在Selenium Google ChromeDriver中禁用图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆