Wikipedia API-生成器查询以查找类别

问题描述 投票:1回答:1

以下查询返回列出为“好文章”的Wikipedia文章(为方便起见,限制为5。)>

https://en.wikipedia.org/w/api.php?action=query&format=json&list=embeddedin&eititle=Template:Good%20article&eilimit=5

这很好,我得到以下结果:

{
"batchcomplete": "",
"continue": {
    "eicontinue": "0|666",
    "continue": "-||"
},
"query": {
    "embeddedin": [
        {
            "pageid": 12,
            "ns": 0,
            "title": "Anarchism"
        },
        {
            "pageid": 307,
            "ns": 0,
            "title": "Abraham Lincoln"
        },
        {
            "pageid": 308,
            "ns": 0,
            "title": "Aristotle"
        },
        {
            "pageid": 339,
            "ns": 0,
            "title": "Ayn Rand"
        },
        {
            "pageid": 627,
            "ns": 0,
            "title": "Agriculture"
        }
    ]
}

现在,我想获取与每篇文章相关的类别,因此我尝试使用'生成器'查询,如此处所述:https://www.mediawiki.org/wiki/API:Query#Generators

我建立了以下URL:https://en.wikipedia.org/w/api.php?action=query&generator=embeddedin&geititle=Template:Good%20article&prop=categories

但是由于某些原因,类别列表仅显示在第一个结果中。

{
"continue": {
    "clcontinue": "12|Articles_with_unsourced_statements_from_July_2019",
    "continue": "||"
},
"query": {
    "pages": {
        "12": {
            "pageid": 12,
            "ns": 0,
            "title": "Anarchism",
            "categories": [
                {
                    "ns": 14,
                    "title": "Category:All articles lacking reliable references"
                },
                {
                    "ns": 14,
                    "title": "Category:All articles with unsourced statements"
                },
                {
                    "ns": 14,
                    "title": "Category:Anarchism"
                },
                {
                    "ns": 14,
                    "title": "Category:Anti-capitalism"
                },
                {
                    "ns": 14,
                    "title": "Category:Anti-fascism"
                },
                {
                    "ns": 14,
                    "title": "Category:Articles containing French-language text"
                },
                {
                    "ns": 14,
                    "title": "Category:Articles containing Spanish-language text"
                },
                {
                    "ns": 14,
                    "title": "Category:Articles lacking reliable references from March 2019"
                },
                {
                    "ns": 14,
                    "title": "Category:Articles prone to spam from November 2014"
                },
                {
                    "ns": 14,
                    "title": "Category:Articles with short description"
                }
            ]
        },
        "307": {
            "pageid": 307,
            "ns": 0,
            "title": "Abraham Lincoln"
        },
        "308": {
            "pageid": 308,
            "ns": 0,
            "title": "Aristotle"
        },
        "339": {
            "pageid": 339,
            "ns": 0,
            "title": "Ayn Rand"
        },
        "627": {
            "pageid": 627,
            "ns": 0,
            "title": "Agriculture"
        },
        "666": {
            "pageid": 666,
            "ns": 0,
            "title": "Alkali metal"
        },
        "674": {
            "pageid": 674,
            "ns": 0,
            "title": "Anatomy"
        },
        "736": {
            "pageid": 736,
            "ns": 0,
            "title": "Albert Einstein"
        },
        "740": {
            "pageid": 740,
            "ns": 0,
            "title": "Allah"
        },
        "746": {
            "pageid": 746,
            "ns": 0,
            "title": "Azerbaijan"
        }
    }
}

我可以选择在第一个查询的结果上使用foreach循环来获取所有相关类别,但如果可能的话,我会发现从一个查询到API所需的信息更加有效。另外,我想了解为什么只显示第一个结果。

谢谢您的帮助!

以下查询返回列出为“好文章”的Wikipedia文章(为方便起见,限制为5条)。 https://en.wikipedia.org/w/api.php?action = query&format = json&list = ...

php bots wikipedia-api mediawiki-api
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.