2

I want to see the 'user(specifically, user's display_name') data using Stackoverflow's API.

I'm using and reading the docs about StackExchange API, and still didn't get the idea about 'fetch' and anything about get the data.

Using 'beautifulsoup' or any crawling code, is it the only way to get the data?

from stackapi import StackAPI

SITE = StackAPI('stackoverflow')
users = SITE.fetch('users')

print(users['items'])
2
  • Please provide enough code so others can better understand or reproduce the problem. Commented Mar 30, 2022 at 5:13
  • The whole point of an API is to provide results in computer-readable format so you don't have to use a scraping tool like BeautifulSoup to extract the useful bits. Commented Mar 30, 2022 at 6:48

1 Answer 1

3

Following the documentation for the StackAPI python library, the method skeleton is fetch(endpoint=None, page=1, key=None, filter='default', **kwargs).

So your api call will look something like:

from stackapi import StackAPI
SITE = StackAPI('stackoverflow')
SITE.page_size = 5 # limits to 5 returned results for demo purpose
users = SITE.fetch('users', filter='!)mYVom7)TA9')
print(users['items'])

where the filter code was obtained from the get users docs for the api.

Returns:

[{'display_name': 'Jon Skeet'}, {'display_name': 'Gordon Linoff'}, {'display_name': 'VonC'}, {'display_name': 'BalusC'}, {'display_name': 'Darin Dimitrov'}]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.