维基百科的API返回排序的数据,而不是随机数据 [英] Wikipedia API returning sorted data instead of random data

查看:238
本文介绍了维基百科的API返回排序的数据,而不是随机数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想生成使用维基百科的API沙盒一类随机文章。搜索结果

I am trying to generate random articles from a category using the Wikipedia API sandbox.

<一个href=\"http://en.wikipedia.org/w/api.php?action=query&list=random&format=jsonfm&rnnamespace=0&generator=categorymembers&gcmtitle=Category%3ATeam%20sports&gcmnamespace=0\" rel=\"nofollow\">http://en.wikipedia.org/w/api.php?action=query&list=random&format=jsonfm&rnnamespace=0&generator=categorymembers&gcmtitle=Category%3ATeam%20sports&gcmnamespace=0

但每当查询时文章是按字母顺序排列,而不是随机返回。 同时将返回相同的一组文章,每次即可。每次检索文章的数目比在类物品的总数少得多。什么是在查询中的错误吗?

But whenever the query is made articles were returned in alphabetical order rather than randomly. Also the same set of articles is returned each time. The number of articles retrieved each time is much lower than the total number of articles in the category. What is the bug in the query?

推荐答案

这是没有意义的使用列表API和一台发电机。大多数查询的API采取一组页面名称/ ID作为输入的,并且该参数可以用发电机代替。名单的API拿不出这样的输入,使他们不会受到影响。

It does not make sense to use a list API with a generator. Most query APIs take a set of pagenames/ids as input, and this parameter can be replaced with a generator. List APIs take no such input so they won't be affected.

什么真正发生的是随机生成API单页(因为它的极限参数默认为1)随机项下;该网页是正确随机并与每一个请求改变,但它并不限于该类别(列表API不工作方式)。从发电机API的回报(这是当然,不是随机的)是在键显示的,因为任何网页传递给随意API中的标题参数都仅仅是项下返回。

What actually happens is that the random API generates a single page (since its limit parameter defaults to 1) under the random key; that page is properly random and changes with every request, but it isn't limited to the category (list APIs don't work that way). The return from the generator API (which is, of course, not random) is displayed under the pages key, since any pages passed to the random API in the title parameter are simply returned under that key.

你可以做的是调用特别声明:RandomInCategory (没有API还相当于),只是重试,直到你得到一个主命名空间的页面。

What you could do is call Special:RandomInCategory (there is no API equivalent yet) and just retry until you get a main namespace page.

这篇关于维基百科的API返回排序的数据,而不是随机数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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