Created
November 29, 2013 08:11
-
-
Save judotens/7702822 to your computer and use it in GitHub Desktop.
Topsy search scraper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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