【发布时间】:2015-07-22 09:35:38
【问题描述】:
我在 python 中使用 twython 库来转储我自己的公共推文。数据以 json 格式下载,参考: https://api.twitter.com/1.1/statuses/home_timeline.json
如何逐行打印所有数据,比如
print "Tweet : %s" %tweet['text']#status
print "Create Time : %s" %tweet['created_at']#time of tweet
print "Geo location : %s" %tweet['geo']#geo location if avail
print "Favorite Count : %s" %tweet['favorite_count']
print "Source : %s" %tweet["source"]
print "Retweeted : %s" %tweet["retweeted"]
print "contributors :%s" %tweet["contributors"]
print "truncated : %s" %tweet["truncated"]
print "is_quote_status : %s" %tweet["is_quote_status"]
print "in_reply_to_status_id : %s" %tweet["in_reply_to_status_id"]
print "Unique ID : %s" %tweet["id"]
print "coordinates : %s" %tweet["coordinates"]
print "in_reply_to_screen_name : %s" %tweet["in_reply_to_screen_name"]
print "retweet_count : %s" %tweet["retweet_count"]
print "in_reply_to_user_id : %s" %tweet["in_reply_to_user_id"]
print "favorited :%s" %tweet["favorited"]
【问题讨论】:
-
如果你有json,你可以使用
json.loads将它转换成pythondict。 -
不要把事情复杂化,你可以使用
Tweepy模块来访问推文。 -
任何示例代码开始。 json输出的格式将在链接api.twitter.com/1.1/statuses/home_timeline.json
-
@zdaR tweepy,像 twython 一样简单吗?您想指出任何优点和缺点吗?没有多少方法可用于用户时间轴tweepy.readthedocs.org/en/v3.2.0/api.html#API.user_timeline
-
也许你可以考虑使用
nltk。有一些新的功能可以读取 twitter jsons,虽然还没有发布。请查看此notebook,Extracting Parts of a Tweet 段。如果您想使用它,您必须下载项目源并将其添加到您的 PYTHONPATH。不知道什么时候真正发布。 (顺便说一句,这是使用twython访问推特。希望对您有所帮助。