2014-10-09 58 views
3

我想在API響應MediaWiki中獲取<math>標記的內容。使用MediaWiki API獲取維基百科數學表達式

我試圖用這個查詢: https://en.wikipedia.org/w/api.php?action=query&prop=extracts&format=xml&titles=delta-v

而且我得到有效的XML文件,而代替 enter image description here

我越來越:

<dl><dd></dd></dl> 

而我想要的是:

<math>\Delta{v} = \int_{t_0}^{t_1} {\frac {|T|} {m}}\, dt</math> 

這可通過「編輯」按鈕在這裏:http://en.wikipedia.org/w/index.php?title=Delta-v&action=edit

這是以某種方式通過API?

回答

4

您需要查詢整個頁面的源代碼,使用MediaWiki的原生API函數:

    https://en.wikipedia.org/w/api.php?action=query&prop=revisions&rvlimit=1&rvprop=content&format=xml&titles=delta-v

這會給你同樣的事情,你看到編輯頁面時。

prop=extracts查詢由擴展TextExtracts實現,並不總是與其他擴展(例如Math)生成的代碼內容一起使用。它可能被認爲是TextExtracts中的一個bug,但鑑於MediaWiki中頁面渲染的複雜性,以及各種擴展添加到內容的方式的數量,它可能永遠不會捕獲所有內容。

+0

非常感謝您! :) – mpestkow 2014-10-09 09:02:13

0

在您的原始鏈接中,您將獲得MathML渲染,包括註釋元素<annotation encoding="application/x-tex">中的TeX代碼。

<dd> 
 
    <span> 
 
    <span> 
 
     <math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle \Delta {v}=\int _{t_{0}}^{t_{1}}{\frac {|T(t)|}{m(t)}}\,dt}"> 
 
     <semantics> 
 
      <mrow class="MJX-TeXAtom-ORD"> 
 
      <mstyle displaystyle="true" scriptlevel="0"> 
 
       <mi mathvariant="normal">Δ</mi> 
 
       <mrow class="MJX-TeXAtom-ORD"> 
 
       <mi>v</mi> 
 
       </mrow> 
 
       <mo>=</mo> 
 
       <msubsup> 
 
       <mo>∫</mo> 
 
       <mrow class="MJX-TeXAtom-ORD"> 
 
        <msub> 
 
        <mi>t</mi> 
 
        <mrow class="MJX-TeXAtom-ORD"> 
 
         <mn>0</mn> 
 
        </mrow> 
 
        </msub> 
 
       </mrow> 
 
       <mrow class="MJX-TeXAtom-ORD"> 
 
        <msub> 
 
        <mi>t</mi> 
 
        <mrow class="MJX-TeXAtom-ORD"> 
 
         <mn>1</mn> 
 
        </mrow> 
 
        </msub> 
 
       </mrow> 
 
       </msubsup> 
 
       <mrow class="MJX-TeXAtom-ORD"> 
 
       <mfrac> 
 
        <mrow> 
 
        <mrow class="MJX-TeXAtom-ORD"> 
 
         <mo stretchy="false">|</mo> 
 
        </mrow> 
 
        <mi>T</mi> 
 
        <mo stretchy="false">(</mo> 
 
        <mi>t</mi> 
 
        <mo stretchy="false">)</mo> 
 
        <mrow class="MJX-TeXAtom-ORD"> 
 
         <mo stretchy="false">|</mo> 
 
        </mrow> 
 
        </mrow> 
 
        <mrow> 
 
        <mi>m</mi> 
 
        <mo stretchy="false">(</mo> 
 
        <mi>t</mi> 
 
        <mo stretchy="false">)</mo> 
 
        </mrow> 
 
       </mfrac> 
 
       </mrow> 
 
       <mspace width="thinmathspace" /> 
 
       <mi>d</mi> 
 
       <mi>t</mi> 
 
      </mstyle> 
 
      </mrow> 
 
      <annotation encoding="application/x-tex">{\displaystyle \Delta {v}=\int _{t_{0}}^{t_{1}}{\frac {|T(t)|}{m(t)}}\,dt}</annotation> 
 
     </semantics> 
 
     </math> 
 
    </span> 
 
    </span> 
 
</dd>