Note that if you use the &indexpageids=true parameter in the API URL, the result will contain an array of "pageids", for example:
str = ` { "query": { "pageids": [ "66984" ], "pages": { "66984": { "pageid": 66984, "ns": 0, "title": "Main Page", "touched": "2012-11-23T06:44:22Z", "lastrevid": 1347044, "counter": "", "length": 28, "redirect": "", "starttimestamp": "2012-12-15T05:21:21Z", "edittoken": "bd7d4a61cc4ce6489e68c21259e6e416+\\" } } } }`
so that you can use pageids[0] to access an ever-changing number, which is likely to make things easier.
source share