如何将推文的文本检索到json文件中

因此,我正在使用twitterAPI进行一个项目,以使用特定的经度和纬度在Twitter上收集不同关键字的推文。我为推文抓取了数据,该数据是每个关键字的字典列表,其中包含以下字段:

dict_keys(['created_at', 'id', 'id_str', 'text', 'truncated', 'entities', 'extended_entities', 'metadata', 'source', 'in_reply_to_status_id', 'in_reply_to_status_id_str', 'in_reply_to_user_id', 'in_reply_to_user_id_str', 'in_reply_to_screen_name', 'user', 'geo', 'coordinates', 'place', 'contributors', 'is_quote_status', 'retweet_count', 'favorite_count', 'favorited', 'retweeted', 'possibly_sensitive', 'lang'])

我现在想将每个关键字x1_tweets,x2_tweets和x3_tweets的文本提取到json文件中

为此,我定义了一个功能:

def save_to_json(obj, filename):
    with open(filename, 'w') as fp:
        json.dump(obj, fp, indent=4, sort_keys=True) 

where the obj is a list of dictionaries and filename is the filename i want to save the document with. When i try to use the function for my use however example save_to_json(x1_tweets, doors) it returns me a file containing everything in it. How should i use the function that it returns me a file containing only tweets? Any help would be appriciated! thanks in advance!

评论