How to get Titles from a Wikipedia Page

淺唱寂寞╮ 提交于 2019-12-11 10:18:49

问题


Is there a direct API call where I can get titles from a wikipedia page.

For e.g. from http://en.wikipedia.org/wiki/Chicago, I want to retrieve the following:

1 History
 1.1 Rapid growth and development
 1.2 20th and 21st centuries
2 Geography
 2.1 Topography
 2.2 Climate
3 Cityscape
 3.1 Architecture
so on -----------

I have looked at http://www.mediawiki.org/wiki/API:Lists/All, but couldn't find an action which gives me above list from a wiki page.


回答1:


What you want is not a list of pages, so it's not on the page you linked to. But it is possible to retrieve the list of section titles of some page. To do that, you use action=parse with prop=sections.

For example, http://en.wikipedia.org/w/api.php?format=xml&action=parse&prop=sections&page=Chicago returns

<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"/>
            …


来源:https://stackoverflow.com/questions/13459598/how-to-get-titles-from-a-wikipedia-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!