是否有仅用于检索内容摘要的 Wikipedia API? [英] Is there a Wikipedia API just for retrieve the content summary?

查看:30
本文介绍了是否有仅用于检索内容摘要的 Wikipedia API?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只需要检索维基百科页面的第一段.

内容必须是 HTML 格式,准备好显示在我的网站上(所以 no BBCode,或维基百科特殊代码!)

解决方案

有一种方法可以获取整个介绍部分"没有任何 HTML 解析!类似于 AnthonyS 的回答 加上一个额外的 explaintext 参数,你可以得到纯文本的介绍部分文本.

查询

以纯文本形式获取 Stack Overflow 的介绍:

使用页面标题:

https://en.wikipedia.org/w/api.php?format=json&action=query&prop=extracts&exintro&explaintext&redirects=1&titles=Stack%20Overflow

或者使用pageids:

https://en.wikipedia.org/w/api.php?format=json&action=query&prop=extracts&exintro&explaintext&redirects=1&pageids=21721040

JSON 响应

(去除警告)

{查询":{页面":{21721040":{pageid":21721040,ns":0,标题":堆栈溢出",摘录":Stack Overflow 是一个私有网站,是 Stack Exchange 网络的旗舰网站,由 Jeff Atwood 和 Joel Spolsky 于 2008 年创建,作为早期问答网站(如 Experts Exchange)的一个更开放的替代品.该网站的名称是在 2008 年 4 月由 Atwood 的流行编程博客 Coding Horror 的读者投票选出的.\n它提供了有关计算机编程的广泛主题的问题和答案.该网站作为用户提问和回答问题的平台,并通过会员资格和积极参与,以类似于维基或 Digg 的方式对问题和答案进行投票或否决并编辑问题和答案.Stack Overflow 的用户可以获得声望点和徽章";例如,一个人因收到向上"而获得 10 个声望点.对一个问题的答案进行投票,并可以获得他们宝贵贡献的徽章,这代表了传统问答网站或论坛的一种游戏化.所有用户生成的内容均根据知识共享属性相同方式共享许可进行许可.问题是关闭的,以便改进低质量的问题.杰夫·阿特伍德 (Jeff Atwood) 在 2010 年表示,重复问题不会被视为问题,但如果此类额外问题通过增加搜索引擎中的相关关键字点击次数来为网站带来额外流量,则它们会构成优势.\n截至 2014 年 4 月,Stack Overflow 已超过 2,700,000注册用户和超过 7,100,000 个问题.根据分配给问题的标签类型,网站上讨论最多的八个主题是:Java、JavaScript、C#、PHP、Android、jQuery、Python 和 HTML."}}}}

文档:API:query/prop=extracts

I need just to retrieve the first paragraph of a Wikipedia page.

Content must be HTML formatted, ready to be displayed on my website (so no BBCode, or Wikipedia special code!)

解决方案

There's a way to get the entire "introduction section" without any HTML parsing! Similar to AnthonyS's answer with an additional explaintext parameter, you can get the introduction section text in plain text.

Query

Getting Stack Overflow's introduction in plain text:

Using the page title:

https://en.wikipedia.org/w/api.php?format=json&action=query&prop=extracts&exintro&explaintext&redirects=1&titles=Stack%20Overflow

Or use pageids:

https://en.wikipedia.org/w/api.php?format=json&action=query&prop=extracts&exintro&explaintext&redirects=1&pageids=21721040

JSON Response

(warnings stripped)

{
    "query": {
        "pages": {
            "21721040": {
                "pageid": 21721040,
                "ns": 0,
                "title": "Stack Overflow",
                "extract": "Stack Overflow is a privately held website, the flagship site of the Stack Exchange Network, created in 2008 by Jeff Atwood and Joel Spolsky, as a more open alternative to earlier Q&A sites such as Experts Exchange. The name for the website was chosen by voting in April 2008 by readers of Coding Horror, Atwood's popular programming blog.\nIt features questions and answers on a wide range of topics in computer programming. The website serves as a platform for users to ask and answer questions, and, through membership and active participation, to vote questions and answers up or down and edit questions and answers in a fashion similar to a wiki or Digg. Users of Stack Overflow can earn reputation points and \"badges\"; for example, a person is awarded 10 reputation points for receiving an \"up\" vote on an answer given to a question, and can receive badges for their valued contributions, which represents a kind of gamification of the traditional Q&A site or forum. All user-generated content is licensed under a Creative Commons Attribute-ShareAlike license. Questions are closed in order to allow low quality questions to improve. Jeff Atwood stated in 2010 that duplicate questions are not seen as a problem but rather they constitute an advantage if such additional questions drive extra traffic to the site by multiplying relevant keyword hits in search engines.\nAs of April 2014, Stack Overflow has over 2,700,000 registered users and more than 7,100,000 questions. Based on the type of tags assigned to questions, the top eight most discussed topics on the site are: Java, JavaScript, C#, PHP, Android, jQuery, Python and HTML."
            }
        }
    }
}

Documentation: API: query/prop=extracts

这篇关于是否有仅用于检索内容摘要的 Wikipedia API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆