维基百科名单=搜索REST API:如何检索也匹配的文章网址 [英] Wikipedia list=search REST API: how to retrieve also Url of matching articles

查看:224
本文介绍了维基百科名单=搜索REST API:如何检索也匹配的文章网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我学习维基百科的REST API,但我没能找到合适的选项也获得网址搜索查询。

这是请求的网址:

<$p$p><$c$c>http://it.wikipedia.org/w/api.php?action=query&list=search&srsearch=calvino&format=xml&srprop=snippet

此请求只输出标题和片段,但对文章任何URL。
我检查了维基百科的API文档列表=搜索查询,但似乎没有选项也获得网址。

最好的问候,
法比奥·布达


解决方案

您可以轻松地自己从标题形成文章的URL。对于维基百科的意大利,这是 http://it.wikipedia.org/wiki/ 随后的文章的URL恩codeD 称号。就这么简单。

这篇文章的实际URL也取代空格用下划线,但你没有这样做,如果你不想,用空格URL重定向到一个与下划线。

编辑:您可以获取URL,但它不可能得到在同一时间搜索相关的信息。要做到这一点,使用列表作为发电机。例如:

<$p$p><$c$c>http://it.wikipedia.org/w/api.php?action=query&generator=search&gsrsearch=calvino&format=xml&gsrprop=snippet&prop=info&inprop=url

但我想改变网页网址的格式是非常不可能的。太多的其他人依赖于

I'm studying Wikipedia REST API but I'm not able to find the right option to get also URLs for a search query.

this is the URL of the request:

http://it.wikipedia.org/w/api.php?action=query&list=search&srsearch=calvino&format=xml&srprop=snippet

this request outputs only the Title and the Snippet but no URLs for articles. I've checked wikipedia API documentation for the list=search query but seems there is no option to get also URLs.

Best Regards, Fabio Buda

解决方案

You can form the URL of the article easily by yourself from the title. For the Italian Wikipedia, it's http://it.wikipedia.org/wiki/ followed by the URL-encoded title of the article. It's as simple as that.

The actual URL of the article also replaces spaces with underscores, but you don't have to do that if you don't want to, the URL with spaces redirects to the one with underscores.

EDIT: You can get the URL, but it's not possible to get search-related information at the same time. To do that, use the list as a generator. For example:

http://it.wikipedia.org/w/api.php?action=query&generator=search&gsrsearch=calvino&format=xml&gsrprop=snippet&prop=info&inprop=url

But I think changing the format of page URLs is very unlikely: too many other people rely on that.

这篇关于维基百科名单=搜索REST API:如何检索也匹配的文章网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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