Wikipedia list=search REST API:如何检索匹配文章的 Url
我正在研究维基百科 REST API,但我无法找到正确的选项来获取搜索查询的 URL。
这是请求的 URL:
http://it.wikipedia.org/w/api.php?action=query&list=search&srsearch=calvino&format=xml&srprop=snippet
此请求仅输出标题和片段,但不输出文章的 URL。 我已经检查了 wikipedia API 文档中的 list=search 查询,但似乎没有选项可以获取 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以根据标题轻松地自行形成文章的 URL。对于意大利语维基百科,它是
http://it.wikipedia.org/wiki/
后跟 URL 编码的文章标题。就这么简单。文章的实际 URL 也将空格替换为下划线,但如果您不想,则不必这样做,带空格的 URL 会重定向到带下划线的 URL。
编辑:您可以获取 URL,但无法同时获取搜索相关信息。为此,请将该列表用作生成器。例如:
但我认为更改页面 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.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:
But I think changing the format of page URLs is very unlikely: too many other people rely on that.
我发现不可能同时检索描述和 url,所以我分成两个 javascript 方法,第一个获取描述,第二个获取 url:
如果您愿意,检索描述:
https://it.wikipedia.org/w/api.php?action=query&list=search&srsearch=Your%20Params&utf8=
检索网址:
https://it.wikipedia.org/w/api.php?action=query&generator=allpages&search=Your%20Params&gapfrom=Your%20Params&gapto=Your%20Params&prop=info&inprop =url&utf8=
I've found impossible to retrieve both description and url at once, so I split in two javascript method, the first get description, the second get url:
If you prefer, to retrieve description:
https://it.wikipedia.org/w/api.php?action=query&list=search&srsearch=Your%20Params&utf8=
to retrieve url:
https://it.wikipedia.org/w/api.php?action=query&generator=allpages&search=Your%20Params&gapfrom=Your%20Params&gapto=Your%20Params&prop=info&inprop=url&utf8=