File tree Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Original file line number Diff line number Diff line change
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 )
You can’t perform that action at this time.
0 commit comments