如何禁用 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/