-
Notifications
You must be signed in to change notification settings - Fork 0
/
scraper.py
28 lines (25 loc) · 1010 Bytes
/
scraper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
###################################################################################
# Twitter API scraper - designed to be forked and used for more interesting things
###################################################################################
import scraperwiki
import simplejson
import urllib2
# Get results from the Twitter API! Change QUERY to your search term of choice.
# Examples: 'PCC "Police Commissioner"
QUERY = 'Beer'
RESULTS_PER_PAGE = '100'
LANGUAGE = 'eng'
NUM_PAGES = 20
for page in range(1, NUM_PAGES+1):
base_url = 'http://search.twitter.com/search.json?q=%s&rpp=%s' \
% (urllib2.quote(QUERY), RESULTS_PER_PAGE)
try:
results_json = simplejson.loads(scraperwiki.scrape(base_url))
for result in results_json['results']:
data = {}
data['id'] = result['id']
data['text'] = result['text']
data['from_user'] = result['from_user']
print data['from_user'], data['text']
except:
pass