使用 API 随机获取一篇包含 conditions/limitations 的维基百科文章
Get a random wikipedia article with some conditions/limitations using the API
所以维基百科的Random Article功能给出了一个随机文章,我也可以使用RandomInCategory
并指定我想要的类别,这就是我需要的。
现在我想获取文章中的所有文本,给出一些 conditions/limitations:
- 只获取文章正文,没有images/link/tables等...
- 忽略某些部分(参考资料、知名人士等...)
- 文章应该有英文版本(命名空间已经满足)和其他语言版本,例如法语.
- 能够指定 category/categories。
我考虑过使用 HTML 解析器来执行此操作,也许可以使用 Ids/Classes/Headers,但我不确定这是否 100% 准确。
维基百科的 API 能以某种方式做到这一点吗?
谢谢!
我在另一个 SO 问题中发现了这个 https://en.wikipedia.org/w/api.php?format=json&action=query&generator=random&grnnamespace=0&prop=revisions&rvprop=content&grnlimit=10,它很有趣,是否可以在此处添加类别条件以及获取语言的能力?
您可以使用 Special:RandomInCategory(没有 API 等价物)。请注意,它并不是真正随机的(不是均匀分布)。除此之外(和命名空间)没有办法添加更多条件。
您可以使用 Petscan to get lists of articles in any particular category (or combinations). I'm not sure of any functionality for checking that other language articles exist automatically, but I presume there are some tools at Wikidata that can help you. You should be able to pass pageids across and get a list of other languages. As for the actual data collection, I'd recommend using the Python library, Beautiful Soup.
所以维基百科的Random Article功能给出了一个随机文章,我也可以使用RandomInCategory
并指定我想要的类别,这就是我需要的。
现在我想获取文章中的所有文本,给出一些 conditions/limitations:
- 只获取文章正文,没有images/link/tables等...
- 忽略某些部分(参考资料、知名人士等...)
- 文章应该有英文版本(命名空间已经满足)和其他语言版本,例如法语.
- 能够指定 category/categories。
我考虑过使用 HTML 解析器来执行此操作,也许可以使用 Ids/Classes/Headers,但我不确定这是否 100% 准确。
维基百科的 API 能以某种方式做到这一点吗?
谢谢!
我在另一个 SO 问题中发现了这个 https://en.wikipedia.org/w/api.php?format=json&action=query&generator=random&grnnamespace=0&prop=revisions&rvprop=content&grnlimit=10,它很有趣,是否可以在此处添加类别条件以及获取语言的能力?
您可以使用 Special:RandomInCategory(没有 API 等价物)。请注意,它并不是真正随机的(不是均匀分布)。除此之外(和命名空间)没有办法添加更多条件。
您可以使用 Petscan to get lists of articles in any particular category (or combinations). I'm not sure of any functionality for checking that other language articles exist automatically, but I presume there are some tools at Wikidata that can help you. You should be able to pass pageids across and get a list of other languages. As for the actual data collection, I'd recommend using the Python library, Beautiful Soup.