I want read the value of "extract" key in a Wikipedia JSON response in Python3. The URL I'm testing with is https://en.wikipedia.org/w/api.php?action=query&titles=San%20Francisco&prop=extracts&format=json.
The response looks like this
{
"batchcomplete": "",
"query": {
"pages": {
"49728": {
"pageid": 49728,
"ns": 0,
"title": "San Francisco",
"extract": "<p><b>San Francisco</b></p>"
}
}
}
}
I removed the content as it was a lot.
Now the problem is how do I read the page number programmatically. The page number changes with different searches. I definitely don't want to hard code the page number. What do I put instead of page number
content = response.query.pages.<page number>.extract
Is there any way to extract the key from the pages tag and then proceed to get it's value?