Twitter Scraper给出420错误

时间:2013-04-25 08:07:39

标签: python twitter scraperwiki

当我使用以下代码来抓取Twitter的推文时,我收到以下错误:

import scraperwiki
import simplejson
import urllib2

# Change QUERY to your search term of choice. 
# Examples: 'newsnight', 'from:bbcnewsnight', 'to:bbcnewsnight'
QUERY = '#opendata'
RESULTS_PER_PAGE = '100'
LANGUAGE = 'en'
NUM_PAGES = 1000 

for page in range(1, NUM_PAGES+1):
    base_url = 'http://search.twitter.com/search.json?q=%s&rpp=%s&lang=%s&page=%s' \
     % (urllib2.quote(QUERY), RESULTS_PER_PAGE, LANGUAGE, page)
    try:
    results_json = simplejson.loads(scraperwiki.scrape(base_url))
    for result in results_json['results']:
        #print result
        data = {}
        data['id'] = result['id']
        data['text'] = result['text']
        data['from_user'] = result['from_user']
        data['created_at'] = result['created_at']
        print data['from_user'], data['text']
        scraperwiki.sqlite.save(["id"], data) 
   except:
    print 'Oh dear, failed to scrape %s' % base_url
    break

失败:420客户端错误(420)响应时间:479毫秒,http://search.twitter.com/search.json?q=opendata&rpp=100&lang=en&page=1

请帮忙。相同的代码似乎与其他人的刮刀一起使用相同的代码here

1 个答案:

答案 0 :(得分:1)

Twitter的版本1搜索和趋势API提供错误代码420,告诉您在您受到限制时“提升您的平静”。有关详细信息,请参阅here