从导航模板中排除链接

问题描述 投票:0回答:1

我知道我可以在我的API请求中使用this获取文章的链接。

我的问题是关于cases of inclusion。通过询问特定文章的链接,我还获得了包含在文章底部的所有navigation templates中的链接。

例如,在询问this article的链接后:

https://en.wikipedia.org/w/api.php?action=query&titles=St%C3%A9phane_Sess%C3%A8gnon&prop=linkshere

我也得到了navigation templates页面底部的链接:

enter image description here

我正在构建一个使用移动版Wikipedia的应用程序,因此页面底部的navigation templates与我的目标无关,因为they are not shown in the mobile version

我想在某种程度上从结果中排除这些链接。我想只获得实际出现在文章正文中的链接,或者至少检测它们是否来自模板。这可能吗?

mediawiki wikipedia wikipedia-api mediawiki-api
1个回答
0
投票

你知道有一个mobile API?它对文章进行了各种转换,使其更适合小屏幕设备,包括删除大多数导航模板。例如:

https://en.wikipedia.org/api/rest_v1/page/mobile-sections/Fort_Horsted

{
  "lead": {
    "ns": 0,
    "id": 35265226,
    "revision": "803745099",
    "lastmodified": "2017-10-04T10:37:41Z",
    "lastmodifier": {
      "user": "InternetArchiveBot",
      "gender": "unknown"
    },
    "displaytitle": "Fort Horsted",
    "normalizedtitle": "Fort Horsted",
    "wikibase_item": "Q5471353",
    "protection": {},
    "editable": true,
    "languagecount": 0,
    "image": {
      "file": "The_British_Army_in_the_United_Kingdom_1939-45_H5865.jpg",
      "urls": {
        "320": "https://upload.wikimedia.org/wikipedia/commons/e/e1/The_British_Army_in_the_United_Kingdom_1939-45_H5865.jpg",
        "640": "https://upload.wikimedia.org/wikipedia/commons/e/e1/The_British_Army_in_the_United_Kingdom_1939-45_H5865.jpg",
        "800": "https://upload.wikimedia.org/wikipedia/commons/e/e1/The_British_Army_in_the_United_Kingdom_1939-45_H5865.jpg",
        "1024": "https://upload.wikimedia.org/wikipedia/commons/e/e1/The_British_Army_in_the_United_Kingdom_1939-45_H5865.jpg"
      }
    },
    "hatnotes": [],
    "geo": {
      "latitude": 51.358,
      "longitude": 0.513
    },
    "sections": [
      {
        "id": 0,
        "text": "<span><p><b>Fort Horsted</b> is a <a href=\"/wiki/Scheduled_monument\" title=\"Scheduled monument\">scheduled monument</a> (Monument Number 416040) that lies in the Horsted Valley to the South of <a href=\"/wiki/Chatham,_Kent\" title=\"Chatham, Kent\">Chatham, Kent</a>, England. It is a late 19th-century Land Fort, and one of six constructed around Chatham and <a href=\"/wiki/Gillingham,_Kent\" title=\"Gillingham, Kent\">Gillingham, Kent</a> to protect <a href=\"/wiki/Chatham_Dockyard\" title=\"Chatham Dockyard\">HM Dockyard Chatham</a> from attack. Originally  proposed in the <a href=\"/wiki/Royal_Commission_on_the_Defence_of_the_United_Kingdom\" title=\"Royal Commission on the Defence of the United Kingdom\">Royal Commission on the Defence of the United Kingdom</a> Report, published in 1860, it and the other land defences were omitted as part of general cost cutting with only the coastal defences on the <a href=\"/wiki/River_Medway\" title=\"River Medway\">River Medway</a> being retained and completed under the original 1860 proposals. It was not until the mid-1870s that a revised program was accepted, which included the construction of a convict prison at <a href=\"/wiki/Borstal,_Rochester\" title=\"Borstal, Rochester\">Borstal, Rochester</a>, to provide low cost labour for the construction of a line of four forts, <a href=\"/wiki/Fort_Borstal\" title=\"Fort Borstal\">Fort Borstal</a>, <a href=\"/wiki/Fort_Bridgewood\" title=\"Fort Bridgewood\">Fort Bridgewood</a>, Fort Horsted and <a href=\"/wiki/Fort_Luton\" title=\"Fort Luton\">Fort Luton</a> (a further three forts were constructed with the use of convict labour). Its construction started in 1879 and was complete by 1889 after much delay.</p></span><figure class=\"mw-default-size\" id=\"mwAg\"><a href=\"/wiki/File:The_British_Army_in_the_United_Kingdom_1939-45_H5865.jpg\" class=\"image\"><img src=\"//upload.wikimedia.org/wikipedia/commons/thumb/e/e1/The_British_Army_in_the_United_Kingdom_1939-45_H5865.jpg/220px-The_British_Army_in_the_United_Kingdom_1939-45_H5865.jpg\" data-file-type=\"bitmap\" height=\"163\" width=\"220\" srcset=\"//upload.wikimedia.org/wikipedia/commons/thumb/e/e1/The_British_Army_in_the_United_Kingdom_1939-45_H5865.jpg/440px-The_British_Army_in_the_United_Kingdom_1939-45_H5865.jpg 2x, //upload.wikimedia.org/wikipedia/commons/thumb/e/e1/The_British_Army_in_the_United_Kingdom_1939-45_H5865.jpg/330px-The_British_Army_in_the_United_Kingdom_1939-45_H5865.jpg 1.5x\"></a><figcaption>A <a href=\"/wiki/QF_12-pounder_12_cwt_AA_gun\" title=\"QF 12-pounder 12 cwt AA gun\">QF 12-pounder 12 cwt AA gun</a> mounted on Albion BY-series truck, December 1940</figcaption></figure>\n<p class=\"skipped\"><span style=\"font-size: small;\"></span></p>\n\n\n\n"
      },
      {
        "id": 1,
        "toclevel": 1,
        "anchor": "Materials",
        "line": "Materials"
      },
      {
        "id": 2,
        "toclevel": 1,
        "anchor": "Armaments",
        "line": "Armaments"
      },
      {
        "id": 3,
        "toclevel": 1,
        "anchor": "World_wars",
        "line": "World wars"
      },
      {
        "id": 4,
        "toclevel": 1,
        "anchor": "The_name",
        "line": "The name"
      },
      {
        "id": 5,
        "toclevel": 1,
        "anchor": "The_fort_today",
        "line": "The fort today"
      },
      {
        "id": 6,
        "toclevel": 1,
        "anchor": "References",
        "line": "References"
      },
      {
        "id": 7,
        "toclevel": 1,
        "anchor": "External_links",
        "line": "External links"
      }
    ]
  },
  "remaining": {
    "sections": [
      {
        "id": 1,
        "text": "\n<p>The fort was constructed almost entirely of <a href=\"/wiki/Concrete\" title=\"Concrete\">concrete</a>, topped with <a href=\"/wiki/Chalk\" title=\"Chalk\">chalk</a> and <a href=\"/wiki/Soil\" title=\"Soil\">earth</a> with no visible concrete exposed from the outside, except from the gorge or rear of the fort. The ditch was protected by two single and one double counterscarp galleries.</p>\n\n",
        "toclevel": 1,
        "line": "Materials",
        "anchor": "Materials"
      },
      {
        "id": 2,
        "text": "\n<p>Although the original plans of the fort proposed fixed armament, by its completion there had been a shift away from fixed armament to moveable guns. The fort would not been armed, unless actual threat materialised and then with moveable field artillery. In the event of actual invasion and an attack on HM Dockyard Chatham, additional field defence would have augmented the forts, with trenches and battery positions. In fact in 1907 during summer manoeuvres such defences were probably constructed.</p>\n\n",
        "toclevel": 1,
        "line": "Armaments",
        "anchor": "Armaments"
      },
      {
        "id": 3,
        "text": "\n<p>Deemed to have become obsolete by 1910, the fort formed part of Chatham's land defences in both World Wars. In <a href=\"/wiki/World_War_I\" title=\"World War I\">World War I</a> brick emplacements and a <a href=\"/wiki/Pillbox_(military)\" title=\"Pillbox (military)\">pillbox</a> were built on the ramparts, and fixed <a href=\"/wiki/Anti-aircraft_gun\" title=\"Anti-aircraft gun\" class=\"mw-redirect\">anti-aircraft guns</a> of an early type were installed (possibly 12pdr coastal defence guns on improvised high angle mountings, not be confused with the later naval version).</p>\n\n",
        "toclevel": 1,
        "line": "World wars",
        "anchor": "World_wars"
      },
      {
        "id": 4,
        "text": "\n<p>The fort was named after a local hamlet. Horsted is speculated to have been named after the legendary Saxon warrior <a href=\"/wiki/Horsa\" title=\"Horsa\" class=\"mw-redirect\">Horsa</a>, who was killed at nearby <a href=\"/wiki/Battle_of_Aylesford\" title=\"Battle of Aylesford\">Aylesford</a> while fighting the Britons.<span class=\"mw-ref\" id=\"cite_ref-1\"><a href=\"#cite_note-1\" style=\"counter-reset: mw-Ref 1;\"><span class=\"mw-reflink-text\">[1]</span></a></span></p>\n\n",
        "toclevel": 1,
        "line": "The name",
        "anchor": "The_name"
      },
      {
        "id": 5,
        "text": "\n<p>The fort survives relatively intact and is currently in use as a <a href=\"/wiki/Business_park\" title=\"Business park\">business park</a>. While it is in relatively good condition, its commercial use has seen some new construction and modification which has seen the significant loss of the original structure and features.</p>\n\n",
        "toclevel": 1,
        "line": "The fort today",
        "anchor": "The_fort_today"
      },
      {
        "id": 6,
        "text": "\n<div class=\"mw-references-wrap\"><ol class=\"mw-references references\"><li id=\"cite_note-1\"> <span id=\"mw-reference-text-cite_note-1\" class=\"mw-reference-text\"><cite class=\"citation web\" id=\"mwLA\"><a rel=\"mw:ExtLink\" href=\"https://www.britannica.com/topic/Hengist\" class=\"external\">\"Hengist and Horsa\"</a>. Encyclopædia Britannica.</cite></span></li></ol></div>\n\n\n",
        "toclevel": 1,
        "line": "References",
        "anchor": "References",
        "isReferenceSection": true
      },
      {
        "id": 7,
        "text": "\n<ul><li> <a rel=\"mw:ExtLink\" href=\"http://www.ecastles.co.uk/chatham.html\" class=\"external\">Map of Chatham's defences</a></li>\n<li> <a rel=\"mw:ExtLink\" href=\"http://www.forthorsted.co.uk/content/history\" class=\"external\">Fort Horsted website history page</a></li>\n<li> <a rel=\"mw:ExtLink\" href=\"https://web.archive.org/web/20120410012117/http://www.undergroundkent.co.uk/fort_horsted.htm\" class=\"external\">Fort Horsted on the Underground Kent website</a> Dead Link</li>\n<li> <a rel=\"mw:ExtLink\" href=\"http://www.pastscape.org.uk/hob.aspx?hob_id=416040&amp;sort=2&amp;type=&amp;rational=a&amp;class1=1&amp;period=None&amp;county=693349&amp;district=786118&amp;parish=None&amp;place=chatham&amp;recordsperpage=10&amp;source=text&amp;rtype=&amp;rnumber=&amp;p=2&amp;move=n&amp;nor=39&amp;recfc=0\" class=\"external\">Pastscape Record Fort Horstead</a></li></ul>\n\n<div role=\"navigation\" class=\"navbox\" aria-labelledby=\"Forts_in_Medway\" style=\"padding:3px\"><table class=\"nowraplinks collapsible autocollapse navbox-inner\" style=\"border-spacing:0;background:transparent;color:inherit\"><tbody><tr><th scope=\"col\" class=\"navbox-title\" colspan=\"2\" style=\"background:lightsteelblue;\"><div class=\"plainlinks hlist navbar mini\"><ul><li class=\"nv-view\"><a href=\"/wiki/Template:Defences_of_medway\" title=\"Template:Defences of medway\"><abbr style=\";background:lightsteelblue;;background:none transparent;border:none;-moz-box-shadow:none;-webkit-box-shadow:none;box-shadow:none;\">v</abbr></a></li><li class=\"nv-talk\"><a href=\"/wiki/Template_talk:Defences_of_medway\" title=\"Template talk:Defences of medway\"><abbr style=\";background:lightsteelblue;;background:none transparent;border:none;-moz-box-shadow:none;-webkit-box-shadow:none;box-shadow:none;\">t</abbr></a></li><li class=\"nv-edit\"><a rel=\"mw:ExtLink\" href=\"//en.wikipedia.org/w/index.php?title=Template:Defences_of_medway&amp;action=edit\" class=\"external\"><abbr style=\";background:lightsteelblue;;background:none transparent;border:none;-moz-box-shadow:none;-webkit-box-shadow:none;box-shadow:none;\">e</abbr></a></li></ul></div><div id=\"Forts_in_Medway\" style=\"font-size:114%;margin:0 4em\">Forts in Medway</div></th></tr><tr><td colspan=\"2\" class=\"navbox-list navbox-odd hlist\" style=\"width:100%;padding:0px\"><div style=\"padding:0em 0.25em\">\n<dl><dt>Medieval</dt>\n<dd> <a href=\"/wiki/Rochester_Castle\" title=\"Rochester Castle\">Rochester Castle</a></dd></dl>\n\n<dl><dt>Tudor</dt>\n<dd> <a href=\"/wiki/Upnor_Castle\" title=\"Upnor Castle\">Upnor Castle</a></dd></dl>\n\n<dl><dt>17th century</dt>\n<dd> <a href=\"/wiki/Cockham_Wood_Fort\" title=\"Cockham Wood Fort\">Cockham Wood Fort</a></dd>\n<dd> <a href=\"/wiki/Fort_Gillingham\" title=\"Fort Gillingham\">Fort Gillingham</a></dd></dl>\n\n<dl><dt>Inner Ring <span style=\"font-weight:normal;\">(Napoleonic)</span></dt>\n<dd> <a href=\"/wiki/Fort_Clarence\" title=\"Fort Clarence\">Fort Clarence</a></dd>\n<dd> <a href=\"/wiki/Fort_Pitt,_Kent\" title=\"Fort Pitt, Kent\">Fort Pitt</a></dd>\n<dd> <a href=\"/wiki/Fort_Amherst\" title=\"Fort Amherst\">Fort Amherst</a></dd></dl>\n\n<dl><dt>Outer Ring <span style=\"font-weight:normal;\">(<a href=\"/wiki/Royal_Commission_on_the_Defence_of_the_United_Kingdom\" title=\"Royal Commission on the Defence of the United Kingdom\">Palmerston</a>)</span></dt>\n<dd> <a href=\"/wiki/Fort_Borstal\" title=\"Fort Borstal\">Fort Borstal</a></dd>\n<dd> <a href=\"/wiki/Fort_Bridgewood\" title=\"Fort Bridgewood\">Fort Bridgewood</a></dd>\n<dd> <a href=\"/wiki/Fort_Darland\" title=\"Fort Darland\">Fort Darland</a></dd>\n<dd> <a href=\"/wiki/Fort_Horsted\" title=\"Fort Horsted\">Fort Horsted</a></dd>\n<dd> <a href=\"/wiki/Fort_Luton\" title=\"Fort Luton\">Fort Luton</a></dd>\n<dd> <a href=\"/wiki/Grange_Redoubt\" title=\"Grange Redoubt\">Grange Redoubt</a></dd>\n<dd> <a href=\"/wiki/Woodlands_Redoubt\" title=\"Woodlands Redoubt\">Woodlands Redoubt</a></dd>\n<dd> <a href=\"/wiki/Fort_Hoo\" title=\"Fort Hoo\">Fort Hoo</a></dd>\n<dd> <a href=\"/wiki/Fort_Darnet\" title=\"Fort Darnet\">Fort Darnet</a></dd></dl>\n</div></td></tr></tbody></table></div>\n\n",
        "toclevel": 1,
        "line": "External links",
        "anchor": "External_links"
      }
    ]
  }
}

(对Stéphane Sessègnon的反应太大,不能包含在这里。)

如果你真的只想要链接,只有非模板链接,我认为不可用。您可以使用像mwparserfromhell这样的东西自己解析它

© www.soinside.com 2019 - 2024. All rights reserved.