gpt4 book ai didi

api - Wikitravel XML 树结构

转载 作者:行者123 更新时间:2023-12-04 05:40:57 28 4
gpt4 key购买 nike

我正在浏览 Wikitravel API,我注意到他们提供的 XML 文件只是将所有信息集中在一个大 blob 中。示例:http://wikitravel.org/en/Special:Export/San_Francisco

有没有办法获得具有特定标题的树木(例如理解、进入、绕过等)?

最佳答案

您可以使用 action=parse 来自 MediaWiki API这样做。

例如,查询 http://wikitravel.org/wiki/en/api.php?format=xml&action=parse&prop=sections&page=San%20Francisco将返回如下内容:

<api>
<parse>
<sections>
<s toclevel="1" level="2" line="Districts" number="1" index="1" fromtitle="San_Francisco" byteoffset="1186" anchor="Districts"/>
<s toclevel="1" level="2" line="Understand" number="2" index="2" fromtitle="San_Francisco" byteoffset="9563" anchor="Understand"/>
<s toclevel="2" level="3" line="History" number="2.1" index="3" fromtitle="San_Francisco" byteoffset="9578" anchor="History"/>
<s toclevel="2" level="3" line="Climate" number="2.2" index="4" fromtitle="San_Francisco" byteoffset="13913" anchor="Climate"/>
<s toclevel="2" level="3" line="Literature" number="2.3" index="5" fromtitle="San_Francisco" byteoffset="16502" anchor="Literature"/>
<s toclevel="2" level="3" line="Movies" number="2.4" index="6" fromtitle="San_Francisco" byteoffset="19404" anchor="Movies"/>
<s toclevel="2" level="3" line="Tourist information" number="2.5" index="7" fromtitle="San_Francisco" byteoffset="23236" anchor="Tourist_information"/>
<s toclevel="1" level="2" line="Talk" number="3" index="8" fromtitle="San_Francisco" byteoffset="24227" anchor="Talk"/>

</sections>
</parse>
</api>

由此,您可以重建截面树。

关于api - Wikitravel XML 树结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11255085/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com