Je souhaite récupérer les données complètes de https://en.wikipedia.org/wiki/Cat . J'ai essayé différentes manières d'utiliser l'API wiki, mais je ne parviens pas à récupérer les données dans Json. Je ne peux récupérer que la première description du chat. Existe-t-il un moyen de récupérer le contenu complet de la page au format Json ?

1
umer 12 févr. 2020 à 14:03

1 réponse

Meilleure réponse

En utilisant Api Sandbox, vous pouvez créer une demande comme ;

http://en.wikipedia.org//w/api.php?action=query&format=json&prop=revisions&titles=Cat&formatversion=2&rvprop=content&rvslots=*

Utilisez format=json pour récupérer le Json et rvprop=content + rvslots=* pour obtenir le contenu concurrent.

Remarque : le contenu est toujours au format MediaWiki

Résultat (découpé) ;

{
    "batchcomplete": true,
    "query": {
        "pages": [
            {
                "pageid": 6678,
                "ns": 0,
                "title": "Cat",
                "revisions": [
                    {
                        "slots": {
                            "main": {
                                "contentmodel": "wikitext",
                                "contentformat": "text/x-wiki",
                                "content": "{{Good article}}\n{{pp-semi-indef|small=yes}}{{pp-move-indef|small=yes}}\n{{short description|Domesticated feline}}\n{{about|the species that is commonly kept as a pet|the cat family|Felidae|other uses|Cat (disambiguation)|and|Cats (disambiguation)}}\n{{technical reasons|Cat #1|the album|Cat 1 (album)}}\n{{Use dmy dates|date=February 2019}}{{Use American English|date=January 2020}}<!-- Per MOS:ENGVAR and MOS:DATEVAR, articles should conform to one overall spelling of English and date format, typically the ones with which it was created when the topic has no strong national ties. This article was created with American English, using international date format (DD Month YYYY), and should continue to be written that way. If there is a compelling reason to change it, propose a change on the talk page. -->\n{{Speciesbox\n|name= Domestic cat\n|status= DOM\n<!-- There has been extensive discussion about the choice of image in this infobox. Before replacing this image with something else, consider if it actually improves on the ENCYCLOPEDIC CRITERIA which led to this choice.... +150000 chars..
                            }
                        }
                    }
                ]
            }
        ]
    }
}

En option ; ajoutez prop=extracts pour modifier la sortie du format MediaWiki afin d'obtenir une réponse « nettoyée » ;

../api.php?action=query&format=json&prop=extracts&titles=Cat&formatversion=2&rvprop=content&rvslots=*
"query": {
        "pages": [
            {
                "pageid": 6678,
                "ns": 0,
                "title": "Cat",
                "extract": "<p class=\"mw-empty-elt\">\n\n</p>\n\n\n\n<p class=\"mw-empty-elt\">\n\n</p>\n<p>The <b>cat</b> (<i>Felis catus</i>) is a small carnivorous mammal. It is the only domesticated species in the family Felidae and often referred to as the <b>domestic cat</b> to distinguish it from wild members of the family. The cat is either a <b>house cat</b>, a <b>farm cat</b> or a <b>feral cat</b>; latter ranges freely and avoids human contact.\nDomestic cats are valued by humans for companionship and for their ability to hunt rodents.  +483000 chars
            }
        ]
    }
3
0stone0 12 févr. 2020 à 12:29