另请参阅维基百科页面的 json 格式的部分

See also part from a json format of a wikipedia page

我想访问维基百科页面中的 “另见” 部分,该部分采用 json 格式。 有没有办法使用维基百科 API 来做到这一点? 还是有其他方法可以做到这一点? 这是我到目前为止编写的代码

import wikipediaapi
wiki_wiki = wikipediaapi.Wikipedia('en')
page_py = wiki_wiki.page('http://en.wikipedia.org/w/api.php?format=json&action=query&titles=SMALL&prop=revisions&rvprop=content')
resp = requests.get(page_py)
data = resp.json()

那个 link 的 json 文件如下所示

{"batchcomplete":"","warnings":{"main":{"*":"Subscribe to the mediawiki-api-announce mailing list at <https://lists.wikimedia.org/mailman/listinfo/mediawiki-api-announce> for notice of API deprecations and breaking changes. Use [[Special:ApiFeatureUsage]] to see usage of deprecated features by your application."},"revisions":{"*":"Because \"rvslots\" was not specified, a legacy format has been used for the output. This format is deprecated, and in the future the new format will always be used."}},"query":{"pages":{"1808130":{"pageid":1808130,"ns":0,"title":"SMALL","revisions":[{"contentformat":"text/x-wiki","contentmodel":"wikitext","*":"{{Infobox programming language\n| name = Small Machine Algol Like Language\n| logo = <!-- Filename only -->\n| logo caption = \n| screenshot = <!-- Filename only -->\n| screenshot caption = \n| paradigms = [[Procedural programming|Procedural]], [[Imperative programming|imperative]], [[Structured programming|structured]], [[Object-oriented programming|object-oriented]]\n| family = [[ALGOL]]\n| designer = Nevil Brownlee\n| developer = [[University of Auckland]]\n| released = {{Start date and age|1980}}<!-- If known, add |mm|dd|df=yes -->\n| latest release version = Final\n| latest release date = {{Start date and age|1985}}<!-- If known, add |mm|dd|df=yes -->\n| typing = \n| scope = \n| programming language = [[Fortran]] IV, SMALL\n| discontinued = Yes\n| platform = [[Mainframe computer|Mainframe]]s: [[Burroughs Corporation|Burroughs]] B6700, [[Digital Equipment Corporation|DEC]] [[PDP-10]]\n| operating system = [[TOPS-10]], VM/[[Conversational Monitor System|CMS]]\n| license = \n| file ext = \n| file format = <!-- or: | file formats = -->\n| website = <!-- {{URL|www.example.com}} -->\n| implementations = \n| dialects = \n| influenced by = [[ALGOL]]\n| influenced = \n}}\n'''Small Machine Algol Like Language''' ('''SMALL'''), is a [[computer programming]] [[programming language|language]] developed by Dr. Nevil Brownlee of the [[University of Auckland]].\n\n==History==\nThe aim of the language was to enable writing [[ALGOL]]-like code that ran on a small machine. It also included the <code>string</code> [[data type]] for easier text manipulation.\n\nSMALL was used extensively from about 1980 to 1985 at Auckland University as a programming teaching aid, and for some internal projects. Originally, it was written in [[Fortran]] IV, to run on a [[Burroughs Corporation]] B6700 [[mainframe computer]]. Subsequently, it was rewritten in SMALL, and ported to a [[Digital Equipment Corporation]] (DEC) [[PDP-10]] mainframe (on the [[operating system]] [[TOPS-10]]) and an IBM S360 mainframe (on the operating system VM [[Conversational Monitor System]] (VM/CMS)).\n\nAbout 1985, SMALL had some [[object-oriented programming]] features added to handle structures (that were missing from the early language), and to formalise file manipulation operations.\n\n==See also==\n*[[Lua (programming language)]]\n*[[Squirrel (programming language)]]\n\n==References==\n{{Reflist}}\n\n==External links==\n*[https://www.caida.org/home/staff/nevil/ Nevil Brownlee staff page, Center for Applied Internet Data Analysis]\n*[https://www.caida.org/~nevil/ Nevil Brownlee personal page, Center for Applied Internet Data Analysis]\n\n{{ALGOL programming}}\n\n[[Category:Algol programming language family]]\n[[Category:Systems programming languages]]\n[[Category:Procedural programming languages]]\n[[Category:Object-oriented programming languages]]\n[[Category:Programming languages created in 1980]]"}]}}}

另请参阅部分应采用 link 形式,可在输出中点击

使用 requests.get()'http://en.wikipedia.org/ ... 你得到它作为 JSON data 这需要大量代码来解析数据并得到 See also.

使用 wiki_wiki.page('SMALL') 您可以将其作为特殊对象获取,所有数据都经过解析,并且可以轻松访问 See more.

等部分
import wikipediaapi

wiki_wiki = wikipediaapi.Wikipedia('en')
page_py = wiki_wiki.page('SMALL')

see_also = page_py.section_by_title("See also")

see_also_links = see_also.text.split('\n')
print('See also:', see_also_links, '\n')

for link in see_also_links:
    page = wiki_wiki.page(link)
    print('--- title:', page.title, '---')
    print(page.summary, '\n')

这给了我来自 See also 的链接,我可以用它来加载下一页

See also: ['Lua (programming language)', 'Squirrel (programming language)']

--- title: Lua (programming language) ---
Lua ( LOO-ə; from Portuguese: lua [ˈlu.(w)ɐ] meaning moon) is a lightweight, high-level, multi-paradigm programming language designed primarily for embedded use in applications. Lua is cross-platform, since the interpreter of compiled bytecode is written in ANSI C, and Lua has a relatively simple C API to embed it into applications.Lua was originally designed in 1993 as a language for extending software applications to meet the increasing demand for customization at the time. It provided the basic facilities of most procedural programming languages, but more complicated or domain-specific features were not included; rather, it included mechanisms for extending the language, allowing programmers to implement such features. As Lua was intended to be a general embeddable extension language, the designers of Lua focused on improving its speed, portability, extensibility, and ease-of-use in development.

--- title: Squirrel (programming language) ---
Squirrel is a high level imperative, object-oriented programming language, designed to be a lightweight scripting language that fits in the size, memory bandwidth, and real-time requirements of applications like video games and embedded systems.
MirthKit, a simple toolkit for making and distributing open source, cross-platform 2D games, uses Squirrel for its platform. It is used extensively by Code::Blocks for scripting and was also used in Final Fantasy Crystal Chronicles: My Life as a King. It is also used in Left 4 Dead 2, Portal 2 and Thimbleweed Park for scripted events and in NewDark, an unofficial Thief 2: The Metal Age engine update, to facilitate additional, simplified means of scripting mission events, aside of the regular C scripting.