我正在尝试解析latest 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>我的问题是,如何获得实际的页面内容和此页面中的所有链接?
谢谢!
发布于 2020-10-01 03:36:36
您下载了错误版本的转储文件。例如,如果你对分类链接感兴趣,你需要下载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。
https://stackoverflow.com/questions/64143707
复制相似问题