Package: gImageGrabber
It provides tools to grab images from a google search by extracting the links of
the images and downloading original  images.This module is written for windows 10 or Ubuntu 16.0 on 64-bit processor.
It uses Selenium to open browser so as to scroll down to get more images than
possible otherwise. Thus itneeds a browserto work correctly. This is ondefaultset to usechrome browserin case of inability to open it Firefox will be used.
The package comes with chromedriver and geckodriver with it.InstallationTo install gImageGrabber do as follow:$pipinstallgImageGrabberThere are two python filesimgScrapeandimgTools.imgScrapehas all the utilities needed to run the script but if you want to have additional control over the functions
you could exploreimgTools.ImportingTo import this module to your script do this :fromgimagegrabberimportimgScrapefromgimagegrabberimportimgToolsFunctionsBuilding URLimgScrape.build_url(search)This is to compose a google search URL for your search term.
To specify your search term usesearchargument of the function to build the URL.Usage:fromgimagegrabberimportimgScrapesearchTerm="kamikaze eminem"url=imgScrape.build_url(searchTerm)print(url)#FOR DEBUG PURPOSEGetting Source DataimgScrape.browser(url, test=False)This to start a browser windows and scroll down the webpage
to let more pictures load.It returns a raw source code data of the webpage encoded inutf-8format.
It takes 2 argumentsurlandtest.urlis the url of the page it needs to open.testis to make the browser scroll down less thus taking less time
to return the source code. This is useful when you are writing or
debugging something in your script.It uses Chrome or Firefox to work so make sure you have Google chrome or Firefox
installed at their default directory.Sometimes you might need to click onshow more imageson webpage to load even more imagesIf you cant seem to open browser make sure you are on 64-bit OS and that you have chrome
or Firefox installed.If you are on 32-bit processor you need to use Firefox and you also have to download 32 bit
driver fromhereand replace it with the
already presentgeckodriver.exesaved indriver folderof the gImageGrabber Module folder.Usage:fromgimagegrabberimportimgScrapesearchTerm="kamikaze eminem"url=imgScrape.build_url(searchTerm)raw_data=imgScrape.browser(url)print(raw_data)#FOR DEBUG PURPOSEExtracting LinksimgScrape.imageLink(html)This extracts the original link of the images from thehtml`(source code) provided.
:code:`htmlis the source code of the google image search page.
It returns a dict with format[ link : file extension ]. If you want
it in[file extension : link]you can useimgTools.invDict()`function from imgToolsUsage:fromgimagegrabberimportimgScrapefromgimagegrabberimportimgToolssearchTerm="kamikaze eminem"debug=Falseurl=imgScrape.build_url(searchTerm)raw_data=imgScrape.browser(url,debug)links=imgScrape.imageLink(raw_data)print(links)#FOR DEBUG PURPOSEprint(imgTools,invDict(links))#FOR DEBUG PURPOSESaving ImagesimgScrape.saveImages(data, name, onlyType)`This saves all the images given to it in a list of format[link: file extension].It takes 3 arguments:dataThis is to provide  dictionary containing links to images in format[link: file extension].nameThis is to provide the name for the folder under which images will be saved.onlyTypeIf you want only a particular file extension then use this mention
that. If not, then pass it a empty string or just don’t use that argument.The format in which it saves images isRoot folder
|-- Search Term
    |-- file extension(eg 'jpg')
        |-- 000001.jpg
        |-- 000002.jpgUsage:fromgimagegrabberimportimgScrapesearchTerm="Kamikaze"extension=''#save all types of imagesurl=imgScrape.build_url(searchTerm)raw_data=imgScrape.browser(url)links=imgScrape.imageLink(raw_data)imgScrape.saveImages(links,searchTerm,extension)Example CodeThis code is included in the package assimpleScript.py.fromimggrabberimportimgScrape# Search termsearch='kamikaze eminem'fType=''# if you want all the files them make it empty stringdebug=Falsehtml=imgScrape.browser(imgScrape.build_url(search),debug)data=imgScrape.imageLink(html)imgScrape.saveImages(data,search,fType)AuthorSaksham Sharma