从维基百科中提取表格数据



是否有任何方法只提取表数据我正试图从特定部分提取表"一年级;来自本文https://en.wikipedia.org/wiki/List_of_motor_racing_circuits_by_FIA_grade使用Api沙盒,但我只得到页面的全部内容。

这是API沙箱中的URL,它为我提供了所有内容
https://en.wikipedia.org/wiki/Special:ApiSandbox#action=parse&format=json&page=列出%20of%20motor%20racing%20circuits%20by%20FIA%20grade&prop=文本

我按照答案中描述的步骤来获得您想要的数据。

这是URL:

https://en.wikipedia.org/wiki/Special:ApiSandbox#action=parse&format=json&page=List%20of%20motor%20racing%20circuits%20by%20FIA%20grade&prop=sections%7Ctext&section=1&disablelimitreport=1&utf8=1

输出包含表和";一年级;部分

这是API沙盒示例。

响应:

{
"parse": {
"title": "List of motor racing circuits by FIA grade",
"pageid": 57151782,
"text": {
"*": "<div class="mw-parser-output"><h2><span class="mw-headline" id="Grade_One">Grade One</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=List_of_motor_racing_circuits_by_FIA_grade&amp;action=edit&amp;section=1" title="Edit section: Grade One">edit</a><span class="mw-editsection-bracket">]</span></span></h2>n<p>There are 40 Grade One circuits for a total of 49 layouts in 27 nations as of December 2021. Circuits holding Grade One certification may host events involving "Automobiles of Groups D (FIA International Formula) and E (Free Formula) with a weight/power ratio of less than 1 kg/hp."<sup id="cite_ref-ISC2019_1-0" class="reference"><a href="#cite_note-ISC2019-1">&#91;1&#93;</a></sup> As such, a Grade One certification is required to host events involving <a href="/wiki/Formula_One" title="Formula One">Formula One</a> cars.<sup id="cite_ref-2" class="reference"><a href="#cite_note-2">&#91;2&#93;</a></sup><sup id="cite_ref-2021_December_list_3-0" class="reference"><a href="#cite_note-2021_December_list-3">&#91;3&#93;</a></sup>n</p>n<table class="wikitable sortable" width="75%" style="font-size: 95%;">n<tbody><tr>n<th>Circuitn</th>n<th>Locationn</th>n<th>Countryn</th>n<th>Layoutn</th>n<th>Lengthn</th>n<th>Continentn</th></tr>n<tr>n<td><a href="/wiki/Albert_Park_Circuit" title="Albert Park Circuit">Albert Park Circuit</a>n</td>n<td><a href="/wiki/Melbourne" title="Melbourne">Melbourne</a>n</td>n<td><span class="flagicon"><img alt="" src="//upload.wikimedia.org/wikipedia/commons/thumb/8/88/Flag_of_Australia_%28converted%29.svg/23px-Flag_of_Australia_%28converted%29.svg.png" decoding="async" width="23" height="12" class="thumbborder" srcset="//upload.wikimedia.org/wikipedia/commons/thumb/8/88/Flag_of_Australia_%28converted%29.svg/35px-Flag_of_Australia_%28converted%29.svg.png 1.5x, //upload.wikimedia.org/wikipedia/commons/thumb/8/88/Flag_of_Australia_%28converted%29.svg/46px-Flag_of_Australia_%28converted%29.svg.png 2x" data-file-width="1280" data-file-height="640" />&#160;</span><a href="/wiki/Australia" title="Australia">Australia</a>n</td>n<td>Grand Prixn</td>n<td>5.279&#160;km (3.280&#160;mi)n</td>n<td>Australian</td></tr>n<tr>[...the rest of the table is shown here]"
},
"sections": [
{
"toclevel": 1,
"level": "2",
"line": "Grade One",
"number": "1",
"index": "1",
"fromtitle": "List_of_motor_racing_circuits_by_FIA_grade",
"byteoffset": 0,
"anchor": "Grade_One"
}
]
}
}

我看不出如何仅返回表,因此,您必须使用脚本从API响应中提取表((。

最新更新