以json格式使用tweepy保存推文

问题描述 投票:0回答:1

我们如何使用json格式的tweepy收集推文并保存到本地磁盘。我需要在Solr中输入json文件以进行索引和标记化。这是我正在使用的代码:

`

 import json
 import tweepy
 from tweepy import OAuthHandler

 ckey=""
 csecret=""
 atoken=""
 asecret=""

 auth = OAuthHandler(ckey, csecret)
 auth.set_access_token(atoken, asecret)

 api = tweepy.API(auth)

 data1 = api.search(q='politics', count = 1)`
python json rest tweepy information-retrieval
1个回答
0
投票

您可以尝试将数据保存为list并将其转储到json文件中,因为您已经导入了json

z = [x for x in data1]

with open('your_data.json', 'w') as out:
    json.dump(z,out)

或者,您可以将z = [x for x in data1]写为:

z = list()
for x in data1:
    z.append(x)

/还

© www.soinside.com 2019 - 2024. All rights reserved.