按类别导出维基百科选项?

发布于 2025-01-01 09:13:21 字数 238 浏览 2 评论 0原文

我知道我可以完整下载维基百科。但我想知道有没有办法按类别下载?他们有特殊导出页面,但写了一个类别(例如文化)添加了儿童页面和另一组类别,因此尝试获取文化中的所有页面将需要“永远”,因为当您提交文化的另一个子类别时,另一个会出现。你们知道还有其他按类别导出的方法吗? (以简单的方式)

I know I can download Wikipedia entirely. But I wonder if there is any way to download it by category? They have the Special Export page but writing a category (e.g. Culture) adds the children pages and another bunch of categories, so trying to get all the pages in Culture is gonna take "forever", because as you submit another sub categories of culture another show up. Do you guys know of any other way to export it by category? (in a simple way)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

坠似风落 2025-01-08 09:13:21

使用 MediaWiki API,您可以使用 MediaWiki API 获取某个类别中所有页面的 wiki 文本="http://www.mediawiki.org/wiki/API%3aCategorymembers" rel="noreferrer">list=categorymembers 作为 prop=revisions 查询,如下所示:

http://en.wikipedia.org/w/api.php?action=query&generator=categorymembers&gcmtitle=类别:文化&gcmnamespace=0&prop=revisions&rvprop=content

此示例链接给出了 类别:维基百科上的文化。您可以添加 gcmlimit=max 参数来获取更多页面,但对于大型类别,您需要处理 查询继续 正确(或使用 MediaWiki API为您处理它们的客户端)。

(但是,此查询不会显示 Category:Culture 的子类别中的页面。如果您也需要这些内容,您可以获取类别中子类别的页面列表使用不带 cmnamespace 的简单 categorymembers 查询并递归遍历结果来收集要导出的文章标题列表。如果这样做,请小心不要陷入任何类别。循环,并且最好这样做在导出页面之前对结果进行健全性检查 - 通过完整的子类别遍历很容易获得比您预期更多的页面。)

Using the MediaWiki API, you can get the wikitext of all pages in a category by using list=categorymembers as a generator for a prop=revisions query, like this:

http://en.wikipedia.org/w/api.php?action=query&generator=categorymembers&gcmtitle=Category:Culture&gcmnamespace=0&prop=revisions&rvprop=content

This example link gives the content of the first 10 articles in Category:Culture on Wikipedia. You can add the gcmlimit=max parameter to get more pages, but for large categories you'll need to handle query continuations properly (or use a MediaWiki API client that handles them for you).

(However, this query won't show pages in subcategories of Category:Culture. If you want those too, you can get a list of the pages and subcategories in a category using a simple categorymembers query without cmnamespace and recurse through the results to collect a list of article titles to export. If you do that, be careful not to get caught in any category loops, and preferably do a sanity check on the results before exporting the pages — it's very easy to get way more pages than you expected from a full subcategory traversal.)

↘紸啶 2025-01-08 09:13:21

我认为没有其他简单的方法可以做到这一点。

我认为你最好的选择是下载所有文章的转储文件(pages-articles,目前英语维基百科为 7.5 GB)并按类别过滤它们,可能使用类别成员转储(类别链接,1 GB)。

另一种选择是执行类似于手动使用 Special:Export 执行的操作,但使用 API 实现自动化

I don't think there is any other simple way to do that.

I think your best bet is to download the dump file of all articles (pages-articles, currently 7.5 GB for the English Wikipedia) and filter them by category, possibly using the category membership dump (categorylinks, 1 GB).

Another option is do something similar to what you would do using Special:Export manually, but automate it using the API.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文