首页 > 编程语言 > 详细

Python 提取Twitter转发推文的元素(比如用户名)

时间:2014-07-24 10:33:35      阅读:532      评论:0      收藏:0      [点我收藏+]

CODE:

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

'''
Created on 2014-7-24
@author: guaguastd
@name: extract_retweet_attributions.py
'''
    
if __name__ == '__main__':

    # 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 search
    from search import twitter_search
    
    # import extract_retweet_id
    from tweet import extract_retweet_id, get_rt_attributions
    
    while 1:
        query = raw_input('\nInput the query (eg. #MentionSomeoneImportantForYou, exit to quit): ')
        
        if query == 'exit':
            print 'Successfully exit!'
            break
        
        search_results = twitter_search(twitter_api, query, max_results=1)
        #print search_results,
        
        # Get the retweet id
        retweets_id = extract_retweet_id(search_results)
        #print retweets_id,
        
        # Get the retweet attribution
        for rid in retweets_id:
            tweet = twitter_api.statuses.show(_id=rid)
            print get_rt_attributions(tweet)
            print

RESULT:

Input the query (eg. #MentionSomeoneImportantForYou, exit to quit): Core Python
Length of statuses 60

[u'ritzylivingwage']


Python 提取Twitter转发推文的元素(比如用户名)

原文:http://blog.csdn.net/guaguastd/article/details/38077763

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!