Skip to content

Instantly share code, notes, and snippets.

@shauvik
Last active August 29, 2015 14:23
Show Gist options
  • Save shauvik/728729b01995936fc15a to your computer and use it in GitHub Desktop.
Save shauvik/728729b01995936fc15a to your computer and use it in GitHub Desktop.
#!/usr/bin/python
import urllib2
import simplejson
#import jdcal
query='Charleston'
#startDate=int(jdcal.gcal2jd(2014,1,1)[0])
#endDate=int(jdcal.gcal2jd(2014,12,31)[0])
# The request also includes the userip parameter which provides the end
# user's IP address. Doing so will help distinguish this legitimate
# server-side traffic from traffic which doesn't come from an end-user.
#url = ('https://ajax.googleapis.com/ajax/services/search/web'
# '?v=1.0&q=%s daterange:%d-%d&userip=128.61.52.180'%(query, startDate, endDate))
url = ('https://ajax.googleapis.com/ajax/services/search/news'
'?v=1.0&q=%s&rsz=8&userip=128.61.52.180'%(query))
print url
request = urllib2.Request(
url, None, {'Referer': 'http://gatech.edu'})
response = urllib2.urlopen(request)
# Process the JSON string.
results = simplejson.load(response)
# PRINT COMPLETE RESULTS.
# print results
#print "-"*80
# PROCESS RESULTS
#print results['responseData'].keys()
rows=results['responseData']['results']
## Row Keys: ['publisher', 'GsearchResultClass', 'clusterUrl', 'titleNoFormatting', 'language', 'title', 'url', 'publishedDate', 'unescapedUrl', 'relatedStories', 'content', 'location', 'signedRedirectUrl', 'image']
for row in rows:
print row['titleNoFormatting']
print row['publishedDate']
print row['unescapedUrl']
print row['content']
print "-"*80
## More results
print results['responseData']['cursor']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment