新浪微博数据挖掘食谱之十三: 微博篇 (批量获取用户的微博)

#!/usr/bin/python 
# -*- coding: utf-8 -*-

'''
Created on 2015-1-9
@author: beyondzhou
@name: harvest_users_weibo.py
'''

# Harvest users weibo
def harvest_users_weibo():
    
    # import 
    import json
    from login import weibo_login
    from statuses import harvest_user_timeline
    
    # Access to sina api
    weibo_api = weibo_login()
    
    screen_name = 'beyondzhou8'
    tweets = harvest_user_timeline(weibo_api, screen_name=screen_name)
    print json.dumps(tweets,  indent=1)
    
if __name__ == '__main__':
    harvest_users_weibo()

# Harvest user weibo
def harvest_user_timeline(weibo_api, screen_name=None, user_id=None, max_results=2000):
    assert (screen_name != None) != (user_id != None),\
        "Must have screen_name or user_id, but not both"
        
    kw = {  # Keyword args for the Weibo API call
        'count': 200,
        'trim_user': 1,
        'since_id' : 1
    }
    
    if screen_name:
        kw['screen_name'] = screen_name
    else:
        kw['user_id'] = user_id
        
    max_pages = 16
    results = []
    tweets = make_weibo_request(weibo_api.statuses.user_timeline.get, **kw)['statuses']
    if tweets is None: # 401 (Not Authorized) - Need to bail out on loop entry
        tweets = []
    results += tweets
    print >> sys.stderr, '
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值