Python: Google Image Downloader

In this blog we will download pictures from google.


1. First of all, let's create a python project.

 

2. Install package with command in project folder.

$ pip install icrawler

3. In main.py we need to initialize google_img_downloader function.

 

from icrawler.builtin import GoogleImageCrawler


def google_img_downloader():
    pass


def main():
    google_img_downloader()


if __name__ == '__main__':
    main()

 

4. Set download direction and start download some pictures.

 

def google_img_downloader():
    crawler = GoogleImageCrawler(storage={'root_dir': './img'})
    crawler.crawl(keyword='Andrew Tate', max_num=5, min_size=(300, 300))

 

Launch main function and we see results:

 

Now, let's download big pictures and add some filters:

 

def google_img_downloader():
    filters = dict(
        type='photo',
        size='large',
        license='noncommercial'
    )

    crawler = GoogleImageCrawler(storage={'root_dir': './img'})
    # crawler.crawl(keyword='Andrew Tate', max_num=5, min_size=(300, 300))
    crawler.crawl(keyword='London England',
                  max_num=5,
                  min_size=(1000, 1000),
                  overwrite=True,
                  filters=filters,
                  file_idx_offset='auto'
                  )

 

Result: