How to block image loading in Selenium?

When web scraping using Selenium we are wasting a lot of connection bandwidth for loading images. Unless we're capturing screenshots our data scrapers don't need to actually see the various visuals like images.

To block images in Selenium we have two options either add imagesEnabled=false flag or set profile.managed_default_content_settings.images value to 2:

from selenium import webdriver
from import Options

options = Options()
options.headless = True

chrome_options = webdriver.ChromeOptions()
# this will disable image loading
# or alternatively we can set direct preference:
    "prefs", {"profile.managed_default_content_settings.images": 2}

driver = webdriver.Chrome(options=options, chrome_options=chrome_options)
Question tagged: Selenium, Python

Related Posts

How to Scrape Google Maps

We'll take a look at to find businesses through Google Maps search system and how to scrape their details using either Selenium, Playwright or ScrapFly's javascript rendering feature - all of that in Python.

Web Scraping with Selenium and Python Tutorial + Example Project

Introduction to web scraping dynamic javascript powered websites and web apps using Selenium browser automation library and Python.

How to Scrape Dynamic Websites Using Headless Web Browsers

Introduction to using web automation tools such as Puppeteer, Playwright, Selenium and ScrapFly to render dynamic websites for web scraping