Skip to content

Instantly share code, notes, and snippets.

@judotens
Created November 29, 2013 08:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save judotens/7702822 to your computer and use it in GitHub Desktop.
Save judotens/7702822 to your computer and use it in GitHub Desktop.
Topsy search scraper
# scrape tweets from topsy.com
import sys, urllib, urllib2, json, random
def search(query):
data = {'q': query, 'type': 'tweet', 'offset': 1, 'perpage': 1000, 'window': 'a', 'sort_method': "-date", 'apikey': '09C43A9B270A470B8EB8F2946A9369F3'}
url = "http://otter.topsy.com/search.js?" + urllib.urlencode(data)
data = urllib2.urlopen(url)
o = json.loads(data.read())
res = o['response']
return res
if __name__ == "__main__":
try: tanya = str(sys.argv[1])
except: print "python " + sys.argv[0] + " <query keyword>"
print "> Querying for", tanya
res = search(tanya)
print "> Total fetched:", str(res['total'])
print "> Here is the preview:"
for i in res['list'][:10]:
print "-->", i['firstpost_date'], i['title']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment