Python 爬行Twitter用户的Friendship图

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图

时间: 2024-10-20 00:55:56

Python 爬行Twitter用户的Friendship图的相关文章

Python 提取Twitter用户的Tweet

CODE: #!/usr/bin/python # -*- coding: utf-8 -*- ''' Created on 2014-7-31 @author: guaguastd @name: harvest_user_tweet.py ''' if __name__ == '__main__': # import json import json # import search from search import search_for_tweet # import harvest_use

Python 分析Twitter用户喜爱的推文

CODE: #!/usr/bin/python # -*- coding: utf-8 -*- ''' Created on 2014-8-5 @author: guaguastd @name: analyze_favorite_tweet.py ''' if __name__ == '__main__': # import json #import json # import search from search import search_for_tweet # import get_fri

Python 获取Twitter用户与Friends和Followers的关系(eg, 交集,差集)

CODE: #!/usr/bin/python # -*- coding: utf-8 -*- ''' Created on 2014-7-30 @author: guaguastd @name: friends_followers_analyzer.py ''' if __name__ == '__main__': # import json #import json # import search from search import search_for_tweet # import ge

Python 获取Twitter用户的所有的friends和followers

CODE: #!/usr/bin/python # -*- coding: utf-8 -*- ''' Created on 2014-7-29 @author: guaguastd @name: friends_followers_fetch.py ''' if __name__ == '__main__': # import json import json # import search from search import search_for_tweet # import get_fr

Python 对Facebook用户Friendship的聚类分析

CODE: #!/usr/bin/python # -*- coding: utf-8 -*- ''' Created on 2014-8-13 @author: guaguastd @name: friendship_graph_construct.py ''' import networkx as nx import requests import json ACCESS_TOKEN = '' # impot login from login import facebook_login #

Python 提取Twitter特定话题中转载tweet的用户

CODE: #!/usr/bin/python # -*- coding: utf-8 -*- ''' Created on 2014-7-7 @author: guaguastd @name: user_retweet_statuses.py ''' if __name__ == '__main__': # import login, see http://blog.csdn.net/guaguastd/article/details/31706155 from login import tw

python初步编写用户登录

python初步编写用户登录 python编写用户登录 用python写一个脚本,使得这个脚本在执行后,可以产生如下的效果: 1.用户的账号为:root 密码为:westos 2.用户账号和密码均输入正确时,输出" login ok !" 3.用户账号输入正确,密码输入错误,会提示密码错误. 4.用户账号输入错误,会提示该用户不存在. 5.用户账号和密码输入错误三次后自动退出并提示输入错误超过三次. 该用户登录的脚本如下所示: #!/usr/bin/env python #coding

Python 可视化Twitter中指定话题中Tweet的词汇频率

CODE: #!/usr/bin/python # -*- coding: utf-8 -*- ''' Created on 2014-7-8 @author: guaguastd @name: plot_frequencies_words.py ''' if __name__ == '__main__': #import json # import Counter from collections import Counter # import search from search impor

Python 查找Twitter中最流行(转载最多)的10个Tweet

CODE: #!/usr/bin/python # -*- coding: utf-8 -*- ''' Created on 2014-7-4 @author: guaguastd @name: find_popular_retweets.py ''' # Finding the most popular retweets def popular_retweets(statuses): retweets = [ # Store out a tuple of these three values.