维基百科列表=搜索 REST API:如何同时检索匹配文章的 URL [英] Wikipedia list=search REST API: how to retrieve also Url of matching articles

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

问题描述

我正在学习 Wikipedia REST API,但我找不到正确的选项来获取搜索查询的 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.

这是请求的 URL:

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

此请求仅输出标题和代码段,但不输出文章的 URL.我已经检查了 wikipedia API 文档中的 list=search 查询,但似乎也没有获取 URL 的选项.

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

推荐答案

您可以从标题中轻松形成文章的 URL.对于意大利语维基百科,它是 http://it.wikipedia.org/wiki/ 后跟 文章的 URL 编码标题.就这么简单.

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.

文章的实际 URL 也会用下划线替换空格,但如果您不想这样做,则不必这样做,带空格的 URL 会重定向到带下划线的 URL.

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.

编辑:您可以获取 URL,但无法同时获取与搜索相关的信息.为此,请将列表用作生成器.例如:

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

但我认为更改页面 URL 格式的可能性很小:太多其他人依赖于此.

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

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

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