[英]How to get full tweet text in retweets (not using tweepy!)?
我有一些包含 twitter 數據的 ndjson 文件。 我遇到了問題,對於轉推,字典的“文本”屬性僅包含前 140 個字符。 我想提取完整的推文。
通過獲取其中一條推文並運行以下代碼:
data.get('includes')['tweets']
我得到以下結果。
[{'attachments': {'media_keys': [‘’1234”]},
'author_id': “1234”,
'conversation_id': “1234”,
'created_at': '2021-02-10T14:27:19.000Z',
'entities': {'annotations': [{'end': 111,
'normalized_text': 'Scotland',
'probability': 0.9519,
'start': 104,
'type': 'Place'}],
'hashtags': [{'end': 50, 'start': 35, 'tag': 'ChineseNewYear'}],
'urls': [{'display_url': 'pic.twitter.com/1234’,
'end': 221,
'expanded_url': ‘urlwuhuu,
'start': 198,
'url': “another one”}]},
'id': “1234”,
'lang': 'en',
'possibly_sensitive': False,
'public_metrics': {'like_count': 7,
'quote_count': 0,
'reply_count': 6,
'retweet_count': 3},
'reply_settings': 'everyone',
'source': 'Twitter Web App',
'text': “FULL TWEET THAT I WANT TO GET”}]
問題是我現在擁有的是一個列表而不是字典。 要獲取推文(在列表末尾),我不能使用.get function 或使用字符串索引。
go 關於這個的最佳方法是什么?
使用列表理解怎么樣,例如:
tweets_list = data.get('includes')['tweets']
tweet_texts = [ tweet['text'] for tweet in tweets_list ] # gets the texts of all tweets, as a list
text = tweet_texts[0] # get “FULL TWEET THAT I WANT TO GET” from your example
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.