Need a proxy solution? Try ScrapeOps and get 1,000 free requests here, or compare all proxy providers here!
ScrapeOps

Disable Images Loading In Python Selenium

Disable Images Loading In Python Selenium
Published Updated

Selenium is a powerful browser automation library that allows you to build bots and scrapers that can load and interact with web pages in the browser. As a result, Selenium is very popular amongst the Python web scraping community.

In this guide for The Python Selenium Web Scraping Playbook, we will look at how to disable Python Selenium from loading images when opening a page.

Unless you actually need to view the page as a real user would or take screenshots of a page then disabling image loading is a great way to speed up your scrapers and reduce bandwidth usage. Saving you both time and money when scraping at scale.

There are two common ways of disabling image loading when using Python Selenium so we will walk through how to use both approaches:


The most common way to disable image loading in Python Selenium is to add the blink-settings=imagesEnabled=false arguement to your webdriver options when configuring the webdriver:

Python
from selenium import webdriver
## Disable Image Loading
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--blink-settings=imagesEnabled=false')
## Add Options to Webdriver
chrome = webdriver.Chrome(chrome_options=chrome_options)
## Make Request
chrome.get("https://www.chocolate.co.uk/collections/all")

Now when you run the script Selenium will load Chocolate.co.uk without loading the images.

Selenium Web Scraping Playbook - No Images Loaded Chocolate.co.ukSelenium Web Scraping Playbook - No Images Loaded Chocolate.co.uk


Disable Selenium Image Loading Using Experimental Options

The other approach to disabling image loading is using experimental options.

Here we will define a experimental option using add_experimental_option and adding our perferences "prefs", {"profile.managed_default_content_settings.images": 2}:

Python
from selenium import webdriver
## Disable Image Loading
chrome_options = webdriver.ChromeOptions()
chrome_options.add_experimental_option(
"prefs", {"profile.managed_default_content_settings.images": 2}
)
## Add Options to Webdriver
chrome = webdriver.Chrome(chrome_options=chrome_options)
## Make Request
chrome.get("https://www.chocolate.co.uk/collections/all")

Again, now when you run the script Selenium will load Chocolate.co.uk without loading the images.

Selenium Web Scraping Playbook - No Images Loaded Chocolate.co.ukSelenium Web Scraping Playbook - No Images Loaded Chocolate.co.uk


More Web Scraping Tutorials

So that's how you can use both authenticated and unauthenticated proxies with Selenium to scrape websites without getting blocked.

If you would like to learn more about Web Scraping with Selenium, then be sure to check out The Selenium Web Scraping Playbook.

Or check out one of our more in-depth guides:

Need help scraping the web?

Then check out ScrapeOps, the complete toolkit for web scraping.

Get 1,000 free API credits