I am new to Python. I want to extract a user bio, answers, questions they made in Stack Overflow.
Can I do that using the API? For example, can I extract the user: name bio and number of questions answered, using the API, from this URL: https://stackoverflow.com/users/4189194/krishna?tab=profile?
1 Answer
The API presents individual features behind individual URLs. The information on the profile page is combined from several sources; to get the details you requested, you will have to submit multiple requests. Probably start at the API "Hello World" Python example and consult the official documentation for the precise API endpoints; for example, https://api.stackexchange.com/2.2/users/874188?site=stackoverflow.com gets me
{"items":[{"badge_counts":{"bronze":263,"silver":203,"gold":24},"account_id":468289,"is_employee":false,"last_modified_date":1617888900,"last_access_date":1617901099,"reputation_change_year":4789,"reputation_change_quarter":319,"reputation_change_month":319,"reputation_change_week":134,"reputation_change_day":28,"reputation":136341,"creation_date":1312274536,"user_type":"registered","user_id":874188,"accept_rate":62,"website_url":"http://triple.ee","link":"https://stackoverflow.com/users/874188/tripleee","profile_image":"https://i.sstatic.net/ZcY77.png?s=128&g=1","display_name":"tripleee"}],"has_more":false,"quota_max":300,"quota_remaining":290}
and https://api.stackexchange.com/2.2/users/874188/posts?site=stackoverflow.com gets me the (beginning of a paginated, newest-first) list of posts by myself (including questions as well as answers, though recently I only have the latter).
I don't see an API endpoint to get the profile information (bio and avatar etc) but those should be simple to scrape as such.