您的位置:首页 > 编程语言 > Python开发

Python 获取Twitter搜索结果

2014-06-28 07:54 447 查看
CODE:

#!/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 world
Length of statuses 100
Length of statuses 200
Length 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": "https://pbs.twimg.com/profile_background_images/378800000058925647/75a82de53c7b8bffd0135b66bdfd6414.png",
"verified": false,
"profile_text_color": "333333",
"profile_image_url_https": "https://pbs.twimg.com/profile_images/485518231499988992/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": "http://pbs.twimg.com/profile_images/485518231499988992/59Z4ScZA_normal.jpeg",
"following": false,
"geo_enabled": false,
"profile_banner_url": "https://pbs.twimg.com/profile_banners/1273625730/1404443951",
"profile_background_image_url": "http://pbs.twimg.com/profile_background_images/378800000058925647/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": "https://abs.twimg.com/images/themes/theme1/bg.png",
"verified": false,
"profile_text_color": "333333",
"profile_image_url_https": "https://pbs.twimg.com/profile_images/472720352250822656/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": "http://pbs.twimg.com/profile_images/472720352250822656/ij-fsPk5_normal.jpeg",
"following": false,
"geo_enabled": false,
"profile_banner_url": "https://pbs.twimg.com/profile_banners/2537411935/1402070046",
"profile_background_image_url": "http://abs.twimg.com/images/themes/theme1/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):
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: