如何从维基百科页面获取标题 [英] How to get Titles from a Wikipedia Page
问题描述
是否有直接的 API 调用可以让我从维基百科页面获取标题.
Is there a direct API call where I can get titles from a wikipedia page.
例如从 http://en.wikipedia.org/wiki/Chicago,我想检索以下内容:
For e.g. from http://en.wikipedia.org/wiki/Chicago, I want to retrieve the following:
1 历史
1.1 快速成长与发展
1.2 20世纪和21世纪
2 地理
2.1 地形
2.2 气候
3 城市景观
3.1 架构
等等-----------
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 -----------
我查看了 http://www.mediawiki.org/wiki/API:列表/全部,但无法从 wiki 页面找到给我以上列表的操作.
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.
推荐答案
您想要的不是页面列表,因此它不在您链接到的页面上.但是可以检索某些页面的部分标题列表.为此,您将 action=parse
与 prop=sections
.
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
.
例如,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"/>
…
这篇关于如何从维基百科页面获取标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!