2017-07-12 28 views
1

私はそのために、私は次のコードを使用しています、tweepyを使用してblockchainのツイートを探しています:解析tweepy応答

認証を:

consumerKey = "" 
consumerSecret = "" 
accessToken = "" 
accessTokenSecret = "" 

auth = tweepy.OAuthHandler(consumerKey, consumerSecret) 
auth.set_access_token(accessToken, accessTokenSecret) 
api = tweepy.API(auth) 

検索:

query = 'blockchain' 
max_tweets = 5 
searched_tweets = [status for status in tweepy.Cursor(api.search, q=query).items(max_tweets)] 

しかし、私はここからデータを解析する方法についてはっきりしていませんが、変数searched_tweetsは1つの要素しか持たないリストです:

print type(searched_tweets) 
print len(searched_tweets) 

<type 'list'> 
5 

最初の要素はtweepy.models.Statusで、解析方法はわかりません。

"Status(contributors=None, truncated=False, text=u'RT @AdEx_Network: A shoutout to Richard Kastelein for mentioning the AdEx crowdsale #ico #tokensale #ad\u2026', is_quote_status=False, in_reply_to_status_id=None, id=884958221147938816L, favorite_count=0, _api=<tweepy.api.API object at 0xb25ec08c>, author=User(follow_request_sent=False, has_extended_profile=False, profile_use_background_image=True, _json={u'follow_request_sent': False, u'has_extended_profile': False, u'profile_use_background_image': True, u'default_profile_image': False, u'id': 846284378112090112L, u'profile_background_image_url_https': None, u'verified': False, u'translator_type': u'none', u'profile_text_color': u'333333', u'profile_image_url_https': u'https://pbs.twimg.com/profile_images/873212431106834432/-QdMHr0M_normal.jpg', u'profile_sidebar_fill_color': u'DDEEF6', u'entities': {u'description': {u'urls': []}}, u'followers_count': 735, u'profile_sidebar_border_color': u'C0DEED', u'id_str': u'846284378112090112', u'profile_background_color': u'F5F8FA', u'listed_count': 0, u'is_translation_enabled': False, u'utc_offset': None, u'statuses_count': 100, u'description': u'', u'friends_count': 126, u'location': u'', u'profile_link_color': u'1DA1F2', u'profile_image_url': u'http://pbs.twimg.com/profile_images/873212431106834432/-QdMHr0M_normal.jpg', u'following': False, u'geo_enabled': False, u'profile_background_image_url': None, u'screen_name': u'AfiniChristy', u'lang': u'id', u'profile_background_tile': False, u'favourites_count': 100, u'name': u'Fitri Christy Afini', u'notifications'" 

答えて

1

ステータスオブジェクトからテキストを取得するには2つの方法があります。まず例えば、単に.textを使用して、リスト内のつぶやきのテキストを取得するので、:これはドキュメントこのあたりに、つぶやきの最後に「...」と切り捨てている

>>> searched_tweets[0].text 
'RT @LiquidHub: The World Of #Cryptocurrency\n\n#Blockchain #Fintech #makeyourownlane #Mpgvip #AI #defstar5 #IOT #Bitcoin #GrowthHacking #Bigd…' 

お知らせステータスオブジェクトからフルテキストを取得するには、リクエストを変更してから.full_textを使用してください: