Google search using python script [closed]
Try this, its very simple to use: https://pypi.python.org/pypi/google
Docs: https://breakingcode.wordpress.com/2010/06/29/google-search-python/
Github: https://github.com/MarioVilas/google
Install this python package and usage is as simple as this:
# Get the first 5 hits for "google 1.9.1 python" in Google Pakistan
from google import search
for url in search('google 1.9.1 python', tld='com.pk', lang='es', stop=5):
print(url)
Maybe, something like this?
import urllib import json as m_json query = raw_input ( 'Query: ' ) query = urllib.urlencode ( { 'q' : query } ) response = urllib.urlopen ( 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0&' + query ).read() json = m_json.loads ( response ) results = json [ 'responseData' ] [ 'results' ] for result in results: title = result['title'] url = result['url'] # was URL in the original and that threw a name error exception print ( title + '; ' + url )
Read the docs http://docs.python.org/
[Edit] As the AJAX API is dead, you can use a third party service, like SerpApi, they do provide a Python library.
it is better suggested to use google apis but a very ugly version.. (alternative to use google api) you can filter content if you want
import os, urllib, sys
filename = 'http://www.google.com/search?' + urllib.urlencode({'q': ' '.join(sys.argv[1:]) })
cmd = os.popen("lynx -dump %s" % filename)
output = cmd.read()
cmd.close()
print output
it will print exactly what ever a browser should display when you search for something on google