我正在尝试从Twitter API中提取tweet,并将其转储为JSON格式。
for tweet in tweepy.Cursor(api.search,q="kmart",count=200,lang="en",tweet_mode='extended').items(1000):
print(tweet.full_text)
with open('tweets.json', 'a') as f:
f.write(json.dumps(tweet._json))
这可以很好地工作,但是在tweets.json文件中只有一行包含所有tweet。如何将每条tweet放在单独的一行中?
此外,在一些推文中,我仍然没有得到完整的推文。为什么会发生这种情况?
发布于 2019-08-22 11:00:30
可以将indent
的值作为参数传递给json.dumps
方法
for tweet in tweepy.Cursor(api.search,q="kmart",count=200,lang="en",tweet_mode='extended').items(1000):
print(tweet.full_text)
with open('tweets.json', 'a') as f:
f.write(json.dumps(tweet._json, indent=4))
https://stackoverflow.com/questions/57600984
复制相似问题