Skip to content

Instantly share code, notes, and snippets.

@seunboy1
Last active May 21, 2020 16:23
Show Gist options
  • Save seunboy1/7a8bd1dcf040d6439ceb5946e39dc1ff to your computer and use it in GitHub Desktop.
Save seunboy1/7a8bd1dcf040d6439ceb5946e39dc1ff to your computer and use it in GitHub Desktop.
from selenium import webdriver
import os
import wget
#adapted from https://gist.github.com/genekogan/ebd77196e4bf0705db51f86431099e57
#input your search item here
searchterm = 'Tomato'
url = "https://www.google.co.in/search?q="+searchterm+"&source=lnms&tbm=isch"
#insert path to chromedriver inside parentheses
browser = webdriver.Chrome()
browser.get(url)
img_count = 0
extensions = { "jpg", "jpeg", "png", "gif" }
if not os.path.exists(searchterm):
os.mkdir(searchterm)
for _ in range(500):
browser.execute_script("window.scrollBy(0,10000)")
html = browser.page_source.split('["')
imges = []
for i in html:
if i.startswith('http') and "https://encrypted" not in i:
if "https://i.ytimg" not in i:
imges.append(i.split('"')[0])
wget.download(i.split('"')[0], "#download path")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment