Python 3 Google Search Sample
Wednesday, 3 February 2010, 172
Sample Google Search Python code
import urllib.request,urllib.parse,urllib.error
print("Google Searcher --- www.m-eken.com v.P5012")
while input("s: Search. q: Quit #: ")=="s":
GWord=input("#: ")
url="http://www.google.com/search?hl=en&q="+"+".join(GWord.split())
print(GWord+"\nsearching... ")
req=urllib.request.Request(url)
req.add_header("User-Agent","Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.2.149.29 Safari/525.13")
print( urllib.request.urlopen(req).read())