Python如何擷取Twitter搜尋結果

來源:互聯網
上載者:User
#!/usr/bin/python # -*- coding: utf-8 -*- '''Created on 2014-06-28@author: guaguastd@name: search_for_tweet.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()        # Show one sample search result by slicing the list...    while 1:        # input the query        query = raw_input('\nInput the query(exit to quit): ')        if query == 'exit':            print 'Successfully exit!'            break                statuses = search_for_tweet(twitter_api, query)        print json.dumps(statuses[0], indent=1)

RESULT:

Input the query(exit to quit): Hello worldLength of statuses 100Length of statuses 200Length of statuses 200{ "contributors": null,  "truncated": false,  "text": "RT @harrystylds: 3 steps to make me the happiest girl in the world:\n\n1.notice and read this\n2.say hello\n3.follow me \n\n@harry_styles i love \u2026",  "in_reply_to_status_id": null,  "id": 485553920056385536,  "favorite_count": 0,  "source": "<a href=\"http://twitter.com/download/iphone\" rel=\"nofollow\">Twitter for iPhone</a>",  "retweeted": false,  "coordinates": null,  "entities": {  "symbols": [],   "user_mentions": [   {    "id": 1273625730,     "indices": [     3,      15    ],     "id_str": "1273625730",     "screen_name": "harrystylds",     "name": "block bc harry"   },    {    "id": 181561712,     "indices": [     118,      131    ],     "id_str": "181561712",     "screen_name": "Harry_Styles",     "name": "Harry Styles"   }  ],   "hashtags": [],   "urls": [] },  "in_reply_to_screen_name": null,  "in_reply_to_user_id": null,  "retweet_count": 1,  "id_str": "485553920056385536",  "favorited": false,  "retweeted_status": {  "contributors": null,   "truncated": false,   "text": "3 steps to make me the happiest girl in the world:\n\n1.notice and read this\n2.say hello\n3.follow me \n\n@harry_styles i love you :) x\nx13,723",   "in_reply_to_status_id": null,   "id": 485530761375006720,   "favorite_count": 0,   "source": "<a href=\"http://twitter.com/download/iphone\" rel=\"nofollow\">Twitter for iPhone</a>",   "retweeted": false,   "coordinates": null,   "entities": {   "symbols": [],    "user_mentions": [    {     "id": 181561712,      "indices": [      101,       114     ],      "id_str": "181561712",      "screen_name": "Harry_Styles",      "name": "Harry Styles"    }   ],    "hashtags": [],    "urls": []  },   "in_reply_to_screen_name": null,   "in_reply_to_user_id": null,   "retweet_count": 1,   "id_str": "485530761375006720",   "favorited": false,   "user": {   "follow_request_sent": false,    "profile_use_background_image": true,    "default_profile_image": false,    "id": 1273625730,    "profile_background_image_url_https": "png/75a82de53c7b8bffd0135b66bdfd6414.png",    "verified": false,    "profile_text_color": "333333",    "profile_image_url_https": "jpeg/59Z4ScZA_normal.jpeg",    "profile_sidebar_fill_color": "DDEEF6",    "entities": {    "description": {     "urls": []    }   },    "followers_count": 21073,    "profile_sidebar_border_color": "FFFFFF",    "id_str": "1273625730",    "profile_background_color": "FFFFFF",    "listed_count": 51,    "is_translation_enabled": false,    "utc_offset": -10800,    "statuses_count": 53222,    "description": "110514",    "friends_count": 7582,    "location": "brasil",    "profile_link_color": "75B1CB",    "profile_image_url": "jpeg/59Z4ScZA_normal.jpeg",    "following": false,    "geo_enabled": false,    "profile_banner_url": "https://pbs.twimg.com/profile_banners/1273625730/1404443951",    "profile_background_image_url": "png/75a82de53c7b8bffd0135b66bdfd6414.png",    "screen_name": "harrystylds",    "lang": "pt",    "profile_background_tile": false,    "favourites_count": 4360,    "name": "block bc harry",    "notifications": false,    "url": null,    "created_at": "Sun Mar 17 00:27:41 +0000 2013",    "contributors_enabled": false,    "time_zone": "Atlantic Time (Canada)",    "protected": false,    "default_profile": false,    "is_translator": false  },   "geo": null,   "in_reply_to_user_id_str": null,   "lang": "en",   "created_at": "Sat Jul 05 21:08:48 +0000 2014",   "in_reply_to_status_id_str": null,   "place": null,   "metadata": {   "iso_language_code": "en",    "result_type": "recent"  } },  "user": {  "follow_request_sent": false,   "profile_use_background_image": true,   "default_profile_image": false,   "id": 2537411935,   "profile_background_image_url_https": "png/bg.png",   "verified": false,   "profile_text_color": "333333",   "profile_image_url_https": "jpeg/ij-fsPk5_normal.jpeg",   "profile_sidebar_fill_color": "DDEEF6",   "entities": {   "description": {    "urls": []   }  },   "followers_count": 3258,   "profile_sidebar_border_color": "C0DEED",   "id_str": "2537411935",   "profile_background_color": "C0DEED",   "listed_count": 3,   "is_translation_enabled": false,   "utc_offset": null,   "statuses_count": 14015,   "description": "",   "friends_count": 1810,   "location": "",   "profile_link_color": "0084B4",   "profile_image_url": "jpeg/ij-fsPk5_normal.jpeg",   "following": false,   "geo_enabled": false,   "profile_banner_url": "https://pbs.twimg.com/profile_banners/2537411935/1402070046",   "profile_background_image_url": "png/bg.png",   "screen_name": "AkkiKhan07",   "lang": "en",   "profile_background_tile": false,   "favourites_count": 1481,   "name": "Aka$h ##",   "notifications": false,   "url": null,   "created_at": "Sat May 31 12:42:38 +0000 2014",   "contributors_enabled": false,   "time_zone": null,   "protected": false,   "default_profile": true,   "is_translator": false },  "geo": null,  "in_reply_to_user_id_str": null,  "lang": "en",  "created_at": "Sat Jul 05 22:40:50 +0000 2014",  "in_reply_to_status_id_str": null,  "place": null,  "metadata": {  "iso_language_code": "en",   "result_type": "recent" }} Input the query(exit to quit): 

返回欄目頁:http://www.bianceng.cnhttp://www.bianceng.cn/Programming/extra/

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.