Llama.new Llama.new -3 years ago 73
Python Question

PRAW: serializing Comment and Submission objects as JSON

I'm currently working on a reddit crawler using praw for some data mining purposes. I would like to crawl comments and submissions from subreddits and then save them in a database or file, preferably in a json format for use later.
I am having trouble trying to serialize the comment and submission objects as JSON objects in python. Is there an existing method or way to do this?
Note: I am also pretty new to python.

Thanks in advance for the help!

Answer Source

UPDATE ---------

Looks like this is no longer possible, hat tip to Antoine

https://github.com/praw-dev/praw/issues/701

I'm not sure if there's a way to serialize what you need but you can save the submission ids with:

some_id = sub.id

and then retrieve them later on with

r.get_submission(submission_id=some_id)

EDIT -----------------------------------------

So did a bit of research and found this: https://github.com/praw-dev/praw/issues/271

So essentially you can turn on storing json with:

r.config.store_json_result = True

You can then access the json data with the json_dict member of the comment or submission.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download