新浪微博数据挖掘食谱之十五: 爬虫篇 (抓取用户的朋友)

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

'''
Created on 2015-1-11
@author: beyondzhou
@name: crawl_friendship_graph.py
'''

# Crawl friendship graph
def crawl_friendship_graph():
    
    # import 
    #import json
    from login import weibo_login
    from users import crawl_weibo_followers
    
    # Access to sina api
    weibo_api = weibo_login()
    
    screen_name = 'beyondzhou8'
    crawl_weibo_followers(weibo_api, screen_name, depth=1, limit=10)
    
if __name__ == '__main__':
    crawl_friendship_graph()

# Crawl a friendship graph
def crawl_weibo_followers(weibo_api, screen_name, limit=1000000, depth=2):
    
    from data import save_to_mongo
    
    # Resolve the ID for screen_name and start working with IDs for consistency in storage
    seed_id = str(weibo_api.users.show.get(screen_name=screen_name)['id'])
    _, next_queue = get_friends_followers_ids(weibo_api, user_id=seed_id, friends_limit=0, followers_limit=limit)
    
    # Sto
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值