我正在尝试使用 Twittter API 和 Python 获取推文的文本
我使用 oauth 登录并获取结果字典:
jsonTweets = json.loads(response)
list = jsonTweets["statuses"] # list of dictionaries
type(jsonTweets) #returns dict
type(list) #returns list
type(list[0]) #return dict (it's a list of dictionaries)
list[0] 是一个字典:
{u'contributors': None, u'truncated': False, u'text': u'RT @Kagame_quotes: "We, the people of #Rwanda, our country has its own problems that we can\u2019t attribute to others, we need to find solution\u2026', u'in_reply_to_status_id': None, u'id': 387905246028394496L, u'favorite_count': 0, u'source': u'<a href="http://twitter.com" rel="nofollow">Twitter Web Client</a>', u'retweeted': False, u'coordinates': None,
ETC...
我只想获取u'text'
键的值(即获取推文)
所以我写:
for item in list:
print item[u'text']
但这给了我错误:
UnicodeEncodeError: 'ascii' codec can't encode character u'\u2019'
in position 91: ordinal not in range(128)
如何获取u'text'
密钥的值?