2

我正在尝试解析最新的 wikisource dump。更具体地说,我想获取Category:Ballads页面下的所有页面。为此,我下载了https://dumps.wikimedia.org/enwikisource/latest/enwikisource-latest-pages-articles.xml.bz2转储。在此转储中,相关页面包含除实际链接之外的所有内容:

<page>
    <title>Category:Ballads</title>
    <ns>14</ns>
    <id>115796</id>
    <revision>
      <id>4753508</id>
      <parentid>4003780</parentid>
      <timestamp>2014-01-25T16:21:08Z</timestamp>
      <contributor>
        <username>EmausBot</username>
        <id>983607</id>
      </contributor>
      <minor />
      <comment>Bot: Migrating 2 interwiki links, now provided by [[Wikipedia:Wikidata|Wikidata]] on [[d:Q8286819]]</comment>
      <model>wikitext</model>
      <format>text/x-wiki</format>
      <text bytes="51" xml:space="preserve">[[Category:Song lyrics]]
[[Category:Poems by form]]</text>
      <sha1>43eusqpjj6kaqcp6nl1tcmo4ass36ia</sha1>
    </revision>
  </page>
  <page>

我的问题是,我如何获得实际的页面内容和该页面中的所有链接?

谢谢!

4

1 回答 1

2

您下载了错误的转储版本。例如,如果您对分类链接感兴趣,则需要下载https://dumps.wikimedia.org/enwikisource/latest/enwikisource-latest-categorylinks.sql.gz

如果您想要 XML 格式,您需要自己从原始 wikitext 解析这些信息。为此,您可以使用https://dumps.wikimedia.org/enwikisource/latest/enwikisource-latest-pages-meta-current.xml.bz2

根据评论编辑:

enwikisource-latest-pages-meta-current.xml不包含有关类别的机器可读信息,它仅包含有关当前页面内容的信息。您需要查找文本 XML 元素,其中包含存储在页面中的原始 wikitext。通常,在内容的末尾,它有这样的内容:

[[Category:American Civil War]]
[[category:American speeches]]

这表明该页面属于“美国内战”和“美国演讲”类别。

如果你想要一个解析的信息,你需要处理 .sql 文件 AFAIK。

于 2020-09-30T19:36:36.237 回答