rsk82
rsk82

Reputation: 29387

How to get total number of edits for a given wikipedia page from the API?

I actually do not want to list each edit, but to get only the count of it.

this data is available for every article on the left panel in link:

https://en.wikipedia.org/w/index.php?title=Wikipedia&action=info

But this produces complete web page with tables, formatting etc and its exhaustive for wikipedia servers. So I ask if is there a way to only get those few numbers and ommit the whole website scraping.

Upvotes: 2

Views: 829

Answers (1)

James Wong
James Wong

Reputation: 4619

Probably not the answer you want but there isn't a way to get this information yet.

As a workaround you can use the prop=revisions to get all the revisions contributed to the article. You will be able to count the rev tag from here:

http://en.wikipedia.org/w/api.php?format=xml&action=query&titles=Wikipedia&prop=revisions&rvprop=ids&rvlimit=max

Alternatively, you can ask YQL to count it for you with the following command:

SELECT * FROM xml 
WHERE url="http://en.wikipedia.org/w/api.php?format=xml&action=query&titles=Wikipedia&prop=revisions&rvprop=ids&rvlimit=max" 
AND itemPath="/api/query/pages/page/revisions/rev"

Example output (Link to full output):

{
    "query": {
        "count": 500, //This is the total amount of edits
        "created": "2014-03-04T02:29:42Z",
        "lang": "en-US",
        "results": {
            "rev": [{
                "parentid": "597995345",
                "revid": "598005528"
            }, {
                "parentid": "597994174",
                "revid": "597995345"
            }, {
                "parentid": "597891867",
                "revid": "597994174"
            }]
        }
    }
}

Unfortunately, the upper limit for users to retrieve revision data is 500 and for bots it's 5000.

To get the exact count, you will have to set up a parser on your server to capture the exact count from the info page whenever a user queries the data from your side.

Upvotes: 5

Related Questions