scrape free stock images from websites using python

scrape free stock images from websites using python

Topics : scrape free stock images from websites using python , scrape images from the website , scrape images using python

problem statements:

  • scrape images from the website
  • scrape images using python
  • How to scrape images from websites
  • images scraping using beautiful soup and requests
  • python images web scraping
  • downloading images using python
  • image scraping
  • image scraping python

scrape free stock images from websites using python – Photos are being used more frequently on websites, blogs, slideshows, and ebooks. The need for photos has increased dramatically and more people are using stock photo agencies to buy their photos and images, protect their companies from copyright issues and utilize the many options that stock photo agencies offer.

If we need free stock images in bulk then downloading it from website is much time consuming and not a easy task,

So can we use python to automate the downloading process of free stock images by writing a few lines of code?

The answer is Yes, Python urllib and Beautiful Soup module allow us to scrape/download images from websites. So I will tell you how to use python to automate the boring stuff of downloading images manually, So without wasting the time let get started our article scrape free stock images from websites using python,

Beautiful Soup is a Python library for pulling data out of HTML and XML files. It works with your favorite parser to provide idiomatic ways of navigating, searching, and modifying the parse tree. It commonly saves programmers hours or days of work.

Make sure you have downloaded and installed python if you haven’t download python yet then follow the tutorial to download python :

Downloading and setting up python

Once you have down with downloading and setting up python Then Next Thing you need to download the Python urllib and Beautiful Soupmodule.

Module You need to scrape free stock images from websites using python?

Just open command prompt and run the following commands

pip install urllib3
pip install bs4

After installing urllib3 Next is to create a python project, If you still don’t know how to create a python project then follow the tutorial link below :

Creating project in python

After this paste the code below in that python file


import urllib.request
import bs4 as bs

term = input("Enter Search term : ")
url = 'https://www.istockphoto.com/search/2/image?phrase='+term 
html = urllib.request.urlopen(url)
soup = bs.BeautifulSoup(html,'lxml') 
for res in soup.findAll('img'):
         num = res.get('src')
         if num in mylist:               
             URL = res.get('src')      
             urllib.request.urlretrieve(URL, term+str(images_scraped)+".jpeg")    
             num = num.split('-')
             num = num[-1]
             print(" item ",images_scraped)
     except Exception as e:     

After running this code. It will input the search time and auto-downloads all available images for that term in the current working directory.

if you can answer the following question that will be helpful for others.

Q1. How can we limit the number of images scraped/downloaded?

Q2. How can we change the directory for images scraped/downloaded?

If you have another efficient way to perform this task of scraping free stock images from websites using python. Please share in the comment section.


Hope you like the article scrape free stock images from websites using python

keep visiting : shaadcoding



  1. This is very interesting post. Thank you for sharing this informative guidelines.

  2. What’s up Dear, are you truly visiting this site on a regular basis,
    if so then you will without doubt take pleasant knowledge.

  3. Amazing! This blog looks just like my old one!
    It’s on a totally different subject but it has pretty much
    the same page layout and design. Wonderful choice of colors!

  4. We stumbled over here coming from a different web page and
    thought I might as well check things out. I like what I see
    so now i’m following you. Look forward to exploring your web page repeatedly.

  5. I think this is one of the most vital info for me. And i am glad reading your article.
    But wanna remark on few general things, The website style is ideal, the articles is
    really excellent : D. Good job, cheers

    • Sorry I don’t have any video explaining that code,but much hopefully it will be shared if i get time from my tough routine 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *