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'])
tripleee
  • 175,061
  • 34
  • 275
  • 318
  • Please provide enough code so others can better understand or reproduce the problem. – Community Mar 30 '22 at 05: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. – tripleee Mar 30 '22 at 06:48

1 Answers1

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'}]
dogekali
  • 91
  • 6