首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >还请参阅维基百科页面的json格式中的部分。

还请参阅维基百科页面的json格式中的部分。
EN

Stack Overflow用户
提问于 2021-05-15 18:58:15
回答 1查看 203关注 0票数 0

我想访问维基百科页面中的“也请参阅”部分,这是一种json格式。有什么方法可以使用维基百科API来实现呢?或者还有别的办法可以做到吗?这是我到目前为止编写的代码

代码语言:javascript
复制
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()

该链接的THe json文件如下所示

代码语言:javascript
复制
{"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]]"}]}}}

也请参阅部分应以在输出中可单击的链接的形式。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-05-15 22:13:06

使用requests.get()'http://en.wikipedia.org/ ...,您可以将其作为JSON data来实现,这需要大量代码来解析数据并获取See also

使用wiki_wiki.page('SMALL'),您可以将其作为特殊对象来获得,该对象已对所有数据进行了解析,可以方便地访问像See more这样的部分。

代码语言:javascript
复制
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的链接,我可以用它加载下一个页面。

代码语言:javascript
复制
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.
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67550276

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档