码迷,mamicode.com
首页 > 编程语言 > 详细

Python 爬行Twitter用户的Friendship图

时间:2014-08-01 09:19:31      阅读:297      评论:0      收藏:0      [点我收藏+]

标签:数据挖掘   twitter   

CODE:

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

'''
Created on 2014-8-1
@author: guaguastd
@name: crawing_friendship_graph.py
'''

if __name__ == '__main__':
    
    # import json
    #import json
    
    # import search
    from search import search_for_tweet
    
    # import get_friends_followers_ids
    from user import crawl_followers
    
    # import login, see http://blog.csdn.net/guaguastd/article/details/31706155
    from login import twitter_login

    # get the twitter access api
    twitter_api = twitter_login()
    
    # import twitter_text
    import twitter_text
    
    while 1:
        query = raw_input('\nInput the query (eg. #MentionSomeoneImportantForYou, exit to quit): ')
        
        if query == 'exit':
            print 'Successfully exit!'
            break
        
        statuses = search_for_tweet(twitter_api, query) 
        ex = twitter_text.Extractor(statuses)     
        
        screen_names = ex.extract_mentioned_screen_names_with_indices()
        screen_names = [screen_name['screen_name']
                        for screen_name in screen_names]
                
        for screen_name in screen_names:
            #print json.dumps(screen_names, indent=1)  
            crawl_followers(twitter_api, screen_name, depth=1, limit=10)

RESULT:

Input the query (eg. #MentionSomeoneImportantForYou, exit to quit): Mining Twitter
Length of statuses 88
Fetched 5000 total followers ids for 15362680
[{u'_id': ObjectId('53dacba0ae6f2217909a0e04'), u'followers': [2371121161L, 403929334, 2696296824L, 2696169230L, 310282374, 315832952, 2450621492L, 1261558134, 16996451, 2440864703L]}, {u'_id': ObjectId('53dacdc8ae6f22172c317a79'), u'followers': [2371121161L, 403929334, 2696296824L, 2696169230L, 310282374, 315832952, 2450621492L, 1261558134, 16996451, 2440864703L]}] 
Input the query (eg. #MentionSomeoneImportantForYou, exit to quit): 


Python 爬行Twitter用户的Friendship图,布布扣,bubuko.com

Python 爬行Twitter用户的Friendship图

标签:数据挖掘   twitter   

原文地址:http://blog.csdn.net/guaguastd/article/details/38330569

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!