zoukankan      html  css  js  c++  java
  • 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('
    Input 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): 


  • 相关阅读:
    视图类,双缓冲,图片资源的显示
    偏好设置
    yii2安装遇到[InvalidArgumentException] Could not find package
    java 回调函数解读
    工具使用——神器mimikatz使用
    cve-2019-0708 远程桌面代码执行漏洞复现
    工具使用--sqlmap使用
    漏洞复现--通达OA前台任意用户伪造登录漏洞
    漏洞复现--cve-2020-1938 Apache tomcat 文件包含漏洞
    ThinkPad T480s 用户指南V4.0--更换键盘部分
  • 原文地址:https://www.cnblogs.com/yfceshi/p/6792752.html
Copyright © 2011-2022 走看看