python - 使用 Python 中的 Selenium 禁用 Chrome 中的图像加载

标签 python image selenium google-chrome selenium-chromedriver

如何禁用 Chrome 中的图像加载

browser.get("chrome://settings/content/images")
time.sleep(5)
images = browser.find_element_by_id('addSite')
images.click()
text = browser.find_element_by_css_selector("[id='input']")
text.send_keys("https://www.instagram.com/")
accept = browser.find_element_by_xpath("//button[text()='Añadir']")
accept.click() 

我试图进入 Chrome 中的设置页面,然后单击被阻止的网站并添加 Instagram,因此它会阻止 Instagram 中的图像,但它找不到页面上的按钮。 有人知道另一种方法吗? 我尝试使用扩展名,但它的 .crx 和 chrome 只喜欢 .crx3

最佳答案

option = webdriver.ChromeOptions()
chrome_prefs = {}
option.experimental_options["prefs"] = chrome_prefs
chrome_prefs["profile.default_content_settings"] = {"images": 2}
chrome_prefs["profile.managed_default_content_settings"] = {"images": 2}
browser = webdriver.Chrome(chrome_options=option)

关于python - 使用 Python 中的 Selenium 禁用 Chrome 中的图像加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63252516/

相关文章:

python - 使用空字典作为默认参数的最 Pythonic 方式是什么?

android - 将图片从Android发送到PC上的Matlab

php - 我想将多个图像添加到 MySQL 数据库中

api - Selenium 和 Postman 集成还是其他方法?

java - 当尝试在 Selenium 中使用 POM 自动化论坛时,我遇到了 java.lang.NoClassDefFoundError...我该如何解决这个问题?

python - 访问 API 时在 Python 中收到请求错误 404

python - 使用正则表达式查找并替换每个匹配的任意数量的元素

python - 在 for 循环中修改列表元素

c# - 在低质量图像中查找简单对象

java - 在哪里查看哪个 JXBrowser 和 Selenium 匹配的版本?