Thelorgoreng

Google Image Search Python

Aug 27th, 2017
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.15 KB | None | 0 0
  1. #####################################################################
  2. #####################################################################
  3. ####                                                            #####
  4. ####                                                            #####
  5. #### #GOOGLEIMAGESEARCH.PY[PYTHON PROGRAMMING] BY ICHINI KANA# #####
  6. ####                   #[A.K.A THELORGORENK]#                   #####
  7. ####                                                            #####
  8. ####                                                            #####
  9. #####################################################################
  10. #####################################################################
  11. import re
  12. if sys.version_info[0] > 2:
  13.   import urllib.request as urlreq
  14. else:
  15.   import urllib2 as urlreq
  16. from urllib.parse import quote
  17. if sys.version_info[0] < 3:
  18.   class urllib:
  19.     parse = __import__("urllib")
  20.     request = __import__("urllib2")
  21.   input = raw_input
  22.   import codecs
  23.   import Queue as queue
  24. else:
  25.   import queue
  26.   import urllib.request
  27.   import urllib.parse
  28.  
  29. def gis():
  30.   cari = input("search... ")
  31.   argss = quote(cari)
  32.   args = argss.split()
  33.   headers = {}
  34.   headers['User-Agent'] = "Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.27 Safari/537.17"
  35.   req = urllib.request.Request("https://www.google.co.id/search?hl=en&authuser=0&site=imghp&tbm=isch&source=hp&biw=1366&bih=623&q=" + "+".join(args), headers = headers)
  36.   resp = urllib.request.urlopen(req).read().decode("utf-8").replace('\n','').replace('\r','').replace('\t','').replace('http://','gis:').replace('https://','gis:')
  37.   anjay = re.findall('<div class="rg_meta">(.*?)</div>', resp)
  38.   setter = list()
  39.   la = "".join(anjay)
  40.   a = re.findall('"gis:(.*?)"', la)
  41.   q = 1
  42.   for result in a:
  43.     if "vignette" not in result and "mhcdn.net" not in result and "wikia.nocookie" not in result and "twimg.com" not in result:
  44.      if ".jpg" in result[4:] or ".gif" in result[4:] or ".png" in result[4:] or ".jpeg" in result:
  45.       setter.append('(%s). http://%s' % (q, result))
  46.       q += 1
  47.   return "Results: \n"+"\n".join(setter[0:5])
  48. print(gis())
Add Comment
Please, Sign In to add comment