Python 提取Twitter tweets中的元素(包含text, screen names, hashtags)

CODE:

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

'''
Created on 2014-7-1
@author: guaguastd
@name: extract_tweet_entities.py
'''

if __name__ == '__main__':
    
    import json
    
    # import search
    from search import search_for_tweet
    
    # 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 tweet
    from tweet import extract_tweet_entities
    
    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)
        status_texts,screen_names,hashtags,words = extract_tweet_entities(statuses)  
                 
        # Explore the first 5 items for each...
        print json.dumps(status_texts[0:5], indent=1)
        print json.dumps(screen_names[0:5], indent=1)
        print json.dumps(hashtags[0:5], indent=1)
        print json.dumps(words[0:5], indent=1)

RESULT:

Input the query (eg. #MentionSomeoneImportantForYou, exit to quit): #MentionSomeoneImportantForYou
Length of statuses 30
[
 "RT @xmlovex: #MentionSomeoneImportantForYou @purpledrauhl_23", 
 "RT @KillahPimpp: #MentionSomeoneImportantForYou @MissRosaa_", 
 "#MentionSomeoneImportantForYou @justinbieber", 
 "\"@KillahPimpp: #MentionSomeoneImportantForYou @_K_L_O_\"", 
 "RT @KillahPimpp: #MentionSomeoneImportantForYou @_K_L_O_"
]
[
 "xmlovex", 
 "KillahPimpp", 
 "MissRosaa_", 
 "justinbieber", 
 "KillahPimpp"
]
[
 "MentionSomeoneImportantForYou", 
 "MentionSomeoneImportantForYou", 
 "MentionSomeoneImportantForYou", 
 "MentionSomeoneImportantForYou", 
 "MentionSomeoneImportantForYou"
]
[
 "RT", 
 "@xmlovex:", 
 "#MentionSomeoneImportantForYou", 
 "@purpledrauhl_23", 
 "RT"
]

Input the query (eg. #MentionSomeoneImportantForYou, exit to quit): 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值