Posted by Daedalus on Mon 6 Apr 16:55
report abuse | View followups from Daedalus | download | new post
- import urllib, httplib
- while 1:
- query=urllib.urlencode({'q':raw_input()})
- start='<h2 class=r style="font-size:138%"><b>'
- end='</b>'
- google=httplib.HTTPConnection("www.google.com")
- google.request("GET","/search?"+query)
- search=google.getresponse()
- data=search.read()
- if data.find(start)==-1: print "Google Calculator results not found."
- else:
- begin=data.index(start)
- result=data[begin+len(start):begin+data[begin:].index(end)]
- result = result.replace("<font size=-2> </font>",",").replace(" × 10<sup>","E").replace("</sup>","")
- print result
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.