Google Image search program 02-02-2014, 04:00 AM
#1
Run down
Searches google for images, then automatically opens them in your browser.
Code
With x = re.finditer('"unescapedUrl":"(.+?)","url":"', xdat), we use regex to find the unescapedUrl with a plus in it. We then create a list using mes = [] and add a links found with the regex into it.
Hope you liked what I coded/programmed. Have sex with it, give it a hickey, just enjoy it.
Searches google for images, then automatically opens them in your browser.
Code
Code:
import webbrowser,re,urllib,urllib.request,sys,random,time
if sys.version_info[0] > 2:
import urllib.request as urlreq
else:
import urllib2 as urlreq
def googleimagesearch():
try:
search = input("What image should we look up? ")
gdata = urlreq.urlopen("http://ajax.googleapis.com/ajax/services/search/images?v=1.0&q=%s" % "+".join(search))
xdat = gdata.read().decode()
x = re.finditer('"unescapedUrl":"(.+?)","url":"', xdat)
mes = []
for m in x:
m = str(m.group(1))
mes.append(m)
link = random.choice(mes)
link = link.replace("https","http")
webbrowser.open('%s' % link)
nxt = input("Would you like to search another image? ")
if nxt == "yes":
googleimagesearch()
elif nxt == "no":
exit()
else:
print("Unknown command, auto restarting."),time.sleep(1),googleimagesearch()
except Exception as e:
print("\n%s\n" % e)
googleimagesearch()With x = re.finditer('"unescapedUrl":"(.+?)","url":"', xdat), we use regex to find the unescapedUrl with a plus in it. We then create a list using mes = [] and add a links found with the regex into it.
Hope you liked what I coded/programmed. Have sex with it, give it a hickey, just enjoy it.
![[Image: BXqGARG.png]](https://i.imgur.com/BXqGARG.png)








![[+]](https://sinister.ly/images/modern/collapse_collapsed.png)