2012-06-29 7 views

답변

3

MediaWiki APIaction=parse을 사용하면됩니다.

예를 들어, 쿼리 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> 

을, 당신은 섹션 트리를 재구성 할 수 있습니다.

+0

모든 제목이 분리되어 있지만 해당 섹션에 포함 된 정보를 포함하도록 확장되지는 않습니다. 이 방법과 확장 된 트리를 모두 얻을 수있는 방법이 있습니까? 감사! – 7ch5

+0

'prop = sections | wikitext'를 사용하여 원본 텍스트를 얻을 수도 있습니다. 텍스트는 섹션으로 나뉘 지 않지만,'byteoffset's를 사용할 수 있어야합니다. – svick

+0

매력처럼 작동합니다. 감사! – 7ch5