Wikipedia API不返回特定文章的链接

时间:2013-05-16 06:45:33

标签: wikipedia wikipedia-api

我有一个查询,可以获取维基百科文章中的所有链接。问题是对于某些页面,它不返回任何链接。

Wikipedia article上有许多链接。 但是,我的查询:

http://en.wikipedia.org/w/api.php?titles=Maramures_County&prop=links&plnamespace=0&pllimit=250&format=xml&action=query

仅返回:

<?xml version="1.0"?>
    <api>
        <query>
            <normalized>
                <n to="Maramures County" from="Maramures_County"/>
            </normalized>
            <pages>
                <page title="Maramures County" ns="0" pageid="3625444">
                    <links>
                        <pl title="Maramureș County" ns="0"/>
                    </links>
            </page>
        </pages>
    </query>
</api>

如果我为另一篇文章运行相同的查询,喜欢“月亮”,我会得到很多结果。

http://en.wikipedia.org/w/api.php?titles=Moon&prop=links&plnamespace=0&pllimit=250&format=xml&action=query

返回

<?xml version="1.0"?>
    <api>
        <query-continue>
            <links plcontinue="19331|0|JSTOR"/>
        </query-continue>
        <query>
            <pages>
                <page title="Moon" ns="0" pageid="19331">
                <links>
                    <pl title="3753 Cruithne" ns="0"/>
                    <pl title="51st state" ns="0"/><pl title="Ablation" ns="0"/>

                    [ ... etc, etc  ...]

我是否对API做错了或者这是一个错误?

1 个答案:

答案 0 :(得分:5)

实际上,文章Maramures County是重定向到Maramureș County(请注意下面的逗号),这意味着它在技术上an article with a single link to the redirect target

要获取链接,您可以使用实际文章的名称:

http://en.wikipedia.org/w/api.php?titles=Maramure%C8%99%20County&prop=links&plnamespace=0&pllimit=250&format=xml&action=query

或者您可以使用redirects参数:

http://en.wikipedia.org/w/api.php?titles=Maramures%20County&prop=links&plnamespace=0&pllimit=250&format=xml&action=query&redirects