0
我想通过分析评论和对每个评论的回复进行解析。但是,我试图避免使用PRAW。这是我现在可以在subreddit中显示每篇文章的标题的代码。但是,如何访问评论栏和答复?有没有什么办法通过JSON而不是通过PRAW解析reddit的评论和回复?
import requests
import json
r = requests.get('http://www.reddit.com/r/wallstreetbets/new.json?count=500', headers = {'User-agent': 'Chrome'})
r_comments = requests.get('https://www.reddit.com/r/wallstreetbets/comments.json')
theJSON = json.loads(r.text)
theJSON_comments = json.loads(r_comments.text)
titles = []
#print(theJSON)
#prints the titles
for child in theJSON['data']['children']:
titles.append(child['data']['title'])
#print(child['data']['title'])
for child2 in theJSON_comments['data']['children']:
print(child2['data'][0])
new.json不会给你一个可预测的评论结构 - 通常回复嵌套在评论的[data] [children]部分,但取决于你的参数(count = 500,在你的情况下)可能会或可能不会。 –