Retrieving text body of answers and comments using Stackexchange API
Asked Answered
C

1

13

I am trying to retrieve the questions, comments on questions, and answers of questions related to Python from stack overflow using Stack exchange API. I want to extract all information including body of text of questions, comments, and answers. For extracting questions, I am using following code:

questions = SITE.fetch('questions', tagged='python', fromdate=from_date, todate=today,filter='!9YdnSIN*P')

This filter returns all information related to question including text body of question. However, when I use the same filter to extract the answer of those questions, I don't get text body of answers. Here is the code:

answers = SITE.fetch('questions/{ids}/answers', ids=[59239886],filter='!9YdnSIN*P')

When I change the value of filter to

'!*SU8CGYZitCB.D*(BDVIficKj7nFMLLDij64nVID)N9aK3GmR9kT4IzT*5iO_1y3iZ)6W.G*'

it started retrieving the text body of answer but it lost other vital information (tags) such as 'question_id' that shows answer related to question. Same problem holds for retrieving information related to comments on questions.

Could anyone guide me how can I get the text body of answers and comments without losing vital information?

Chondro answered 14/12, 2019 at 22:57 Comment(0)
A
8

Just use withbody filter.

Example:

from pprint import pprint

from stackapi import StackAPI

SITE = StackAPI('stackoverflow')

pprint(SITE.fetch('questions/{ids}', ids=[59239886], filter='withbody'))
pprint(SITE.fetch('questions/{ids}/answers', ids=[59239886], filter='withbody'))

Using this filter it outputs all bodies and tags and everything

Aegospotami answered 15/12, 2019 at 0:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.