8000 initial commit · Rohit6458/Image-Scraping-Python@f44362d · GitHub
[go: up one dir, main page]

Skip to content

Commit f44362d

Browse files
committed
initial commit
0 parents  commit f44362d

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

main.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import bs4
2+
import requests
3+
import shutil
4+
import os
5+
6+
GOOGLE_IMAGE = \
7+
'https://www.google.com/search?site=&tbm=isch&source=hp&biw=1873&bih=990&'
8+
9+
10+
def extract(data, quantity):
11+
URL_input = GOOGLE_IMAGE + 'q=' + data
12+
print('Fetching from url =', URL_input)
13+
URLdata = requests.get(URL_input)
14+
soup = bs4.BeautifulSoup(URLdata.text, "html.parser")
15+
ImgTags = soup.find_all('img')
16+
i = 0
17+
print('Please wait..')
18+
while i < quantity:
19+
20+
for link in ImgTags:
21+
try:
22+
images = link.get('src')
23+
ext = images[images.rindex('.'):]
24+
if ext.startswith('.png'):
25+
ext = '.png'
26+
elif ext.startswith('.jpg'):
27+
ext = '.jpg'
28+
elif ext.startswith('.jfif'):
29+
ext = '.jfif'
30+
elif ext.startswith('.com'):
31+
ext = '.jpg'
32+
elif ext.startswith('.svg'):
33+
ext = '.svg'
34+
data = requests.get(images, stream=True)
35+
filename = str(i) + ext
36+
with open(filename, 'wb') as file:
37+
shutil.copyfileobj(data.raw, file)
38+
i += 1
39+
except:
40+
pass
41+
print('\t\t\t Downloaded Successfully..\t\t ')
42+
43+
44+
data = input('What are you looking for? ')
45+
quantity = int(input('How many photos you want? '))
46+
extract(data, quantity)

0 commit comments

Comments
 (0)
0