diff --git a/main.py b/main.py deleted file mode 100644 index a632798..0000000 --- a/main.py +++ /dev/null @@ -1,52 +0,0 @@ -''' -Author - Aditya Mangal -Date - 27 october 2020 -Purpose - Python mini task -''' - -import bs4 -import requests -import shutil -import os - -GOOGLE_IMAGE = \ - 'https://www.google.com/search?site=&tbm=isch&source=hp&biw=1873&bih=990&' - - -def extract(data, quantity): - URL_input = GOOGLE_IMAGE + 'q=' + data - print('Fetching from url =', URL_input) - URLdata = requests.get(URL_input) - soup = bs4.BeautifulSoup(URLdata.text, "html.parser") - ImgTags = soup.find_all('img') - i = 0 - print('Please wait..') - while i < quantity: - - for link in ImgTags: - try: - images = link.get('src') - ext = images[images.rindex('.'):] - if ext.startswith('.png'): - ext = '.png' - elif ext.startswith('.jpg'): - ext = '.jpg' - elif ext.startswith('.jfif'): - ext = '.jfif' - elif ext.startswith('.com'): - ext = '.jpg' - elif ext.startswith('.svg'): - ext = '.svg' - data = requests.get(images, stream=True) - filename = str(i) + ext - with open(filename, 'wb') as file: - shutil.copyfileobj(data.raw, file) - i += 1 - except: - pass - print('\t\t\t Downloaded Successfully..\t\t ') - - -data = input('What are you looking for? ') -quantity = int(input('How many photos you want? ')) -extract(data, quantity)