The Friendship diagram of a Python crawling Twitter user

Source: Internet
Author: User

The Friendship diagram of a Python crawling Twitter user

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 TwitterLength of statuses 88Fetched 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): 


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.