Share Pastebin
Guest
Public paste!

Daedalus

By: a guest | Apr 6th, 2009 | Syntax: Python | Size: 0.62 KB | Hits: 111 | Expires: Never
Copy text to clipboard
  1. import urllib, httplib
  2.  
  3. while 1:
  4.     query=urllib.urlencode({'q':raw_input()})
  5.  
  6.     start='<h2 class=r style="font-size:138%"><b>'
  7.     end='</b>'
  8.  
  9.     google=httplib.HTTPConnection("www.google.com")
  10.     google.request("GET","/search?"+query)
  11.     search=google.getresponse()
  12.     data=search.read()
  13.  
  14.     if data.find(start)==-1: print "Google Calculator results not found."
  15.     else:
  16.         begin=data.index(start)
  17.         result=data[begin+len(start):begin+data[begin:].index(end)]
  18.         result = result.replace("<font size=-2> </font>",",").replace(" &#215; 10<sup>","E").replace("</sup>","")
  19.         print result