I want to read the value of the "extract" key in the 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 answer is as follows
{
"batchcomplete": "",
"query": {
"pages": {
"49728": {
"pageid": 49728,
"ns": 0,
"title": "San Francisco",
"extract": "<p><b>San Francisco</b></p>"
}
}
}
}
I deleted the content because it was a lot.
Now the problem is how to programmatically read the page number. The page number changes with different search queries. I definitely don't want to hardcode the page number. What I set instead of page number
content = response.query.pages.<page number>.extract
Is there a way to extract the key from the page tag and then move on to its value?
source
share