Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Topsy search scraper
# scrape tweets from
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 = "" + urllib.urlencode(data)
data = urllib2.urlopen(url)
o = json.loads(
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
You can’t perform that action at this time.