Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
vivek-vijayan authored Sep 20, 2022
1 parent 8e3bb02 commit ed3ff2f
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions Google_Image_Scrapper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# %% [markdown]
# ## Python Google image scrapper
# Python program to get the images from the google based on the query search -
#
# - This program can be used to collect the `Train & Test data` for the `Neural Network`

# %%
from selenium import webdriver
from bs4 import BeautifulSoup
import os
import base64

# %%
# Getting the chrome web driver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager

driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))

searchitem = str(input("Enter the search query")).strip()
searchitem.replace(" ", "+")

driver.get(
"https://www.google.com/search?q=" + searchitem + "&source=lnms&tbm=isch&sa=X"
)
content = driver.page_source
soup = BeautifulSoup(content)

filename_number = 0

os.chdir(os.getcwd())
os.mkdir(searchitem)
os.chdir(os.getcwd() + "/" + searchitem)

for a in soup.findAll("img", attrs={"class": "rg_i Q4LuWd"}):
try:
decodedImage = base64.b64decode(a.get_attribute_list(key="src")[0][23:])
img_file = open( searchitem + str(filename_number) +".jpeg", "wb")
img_file.write(decodedImage)
img_file.close()
filename_number += 1
except:
pass

print("Action completed.")



0 comments on commit ed3ff2f

Please sign in to comment.