Scraping immediately from google images!

Introduction

It is troublesome to save images one by one from image search and collect images, so I found a driver that I should look for, so I will try to summarize it with my own satisfaction.

Preparation

Install google_images_dwonload Page ⇒

$pip install google_images_download
$pip install os
$pip install glob
$pip install chromedriver

Is required, so install it. If there is no application "chromedriver" in the chromedriver, https://chromedriver.chromium.org/downloads Download more and store it in the chromedriver file.

That's all there is to it

environment

・ Pycharm ・ Python 3.7.4 ・ Windows10

Source code

import statement

from google_images_download import google_images_download
import glob
import os

contents This time, the search word is "ONE OK ROCK". Set limit = 100 and set the number of images to 100.

config = {
    "Records": [
        {
            "keywords": "ONE OK ROCK LIVE",
            "no_numbering": True,
            "limit": 100,
            "output_directory": "images",
            "image_directory": "ONE OK ROCK",
            "chromedriver": "C\\[path to chromedirver]\chromedriver\chromedriver.exe",

        }
    ]
}

Write the path to the chrome driver firmly.

response = google_images_download.googleimagesdownload()
for rc in config["Records"]:
    response.download(rc)

For the time being, omit the gif image. (Because it's annoying)

gifImgs = glob.glob("images" + os.sep + "*" + os.sep + "*.gif")
print(f"removing gif files: {len(gifImgs)} files")
_ = [os.remove(f) for f in gifImgs]

You can get it by doing the above in order.

result

スクリーンショット (18).png

at the end

This scraping is good for gathering information and is very convenient. It's quite different from getting an image from a page, so I'll write about that in a separate article. It's only written briefly, so check out the details.

Recommended Posts

Scraping immediately from google images!
Scraping 100 Fortnite images
Save dog images from Google image search
[Python] Download original images from Google Image Search
Image scraping ②-Get images from bing, yahoo, Flickr
Scraping google search (image)
Automatically download images with scraping
Save images with web scraping
Scraping member images from the official website of Sakamichi Group
Download images from "Irasutoya" using Scrapy
Geotag prediction from images using DNN
Detect post-it notes from whiteboard images
Generate daily reports from Google Calendar
GAN: DCGAN Part1 --Scraping Web images
Forcibly use Google Translate from python
Java 1 1 support from Google App Engine
Auth.py from Google BigQuery (O'Reilly book)
Extract text from images in Python
Post images from Python to Tumblr
Snippets (scraping) registered in Google Colaboratory
Image processing | predicting species from images
Nogizaka46 Get blog images by scraping
Use Google Analytics API from Python
[Python] Scraping lens information from Kakaku.com