【问题标题】:How to get Titles from a Wikipedia Page如何从维基百科页面获取标题
【发布时间】:2012-11-19 18:10:28
【问题描述】:

是否有直接的 API 调用可以让我从维基百科页面获取标题。

例如来自http://en.wikipedia.org/wiki/Chicago,我想检索以下内容:

1 历史
1.1 快速成长和发展
1.2 20 世纪和 21 世纪
2 地理
2.1 地形
2.2 气候
3 城市景观
3.1 架构
以此类推-----------

我查看了http://www.mediawiki.org/wiki/API:Lists/All,但在 wiki 页面上找不到可以为我提供上述列表的操作。

【问题讨论】:

    标签: wikipedia wikipedia-api


    【解决方案1】:

    您想要的不是页面列表,因此它不在您链接到的页面上。但是可以检索某些页面的部分标题列表。为此,您可以使用 action=parse 和 prop=sections。

    例如,http://en.wikipedia.org/w/api.php?format=xml&action=parse&prop=sections&page=Chicago 返回

    <api>
        <parse title="Chicago">
            <sections>
                <s toclevel="1" level="2" line="History" number="1" index="1" fromtitle="Chicago" byteoffset="8123" anchor="History"/>
                <s toclevel="2" level="3" line="Rapid growth and development" number="1.1" index="2" fromtitle="Chicago" byteoffset="12922" anchor="Rapid_growth_and_development"/>
                <s toclevel="2" level="3" line="20th and 21st centuries" number="1.2" index="3" fromtitle="Chicago" byteoffset="21558" anchor="20th_and_21st_centuries"/>
                <s toclevel="1" level="2" line="Geography" number="2" index="4" fromtitle="Chicago" byteoffset="28176" anchor="Geography"/>
                …
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多