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.
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
・ Pycharm ・ Python 3.7.4 ・ Windows10
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.
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