解析维基百科转储 [英] Parsing a Wikipedia dump

查看:106
本文介绍了解析维基百科转储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,使用此Wikipedia转储:

For example using this Wikipedia dump:

http://en.wikipedia.org/w/api.php?action=query&prop=revisions&titles=lebron%20james&rvprop=content&redirects=true&format=xmlfm

是否存在用于Python的现有库,可用于创建带有主题和值的映射的数组?

Is there an existing library for Python that I can use to create an array with the mapping of subjects and values?

例如:

{height_ft,6},{nationality, American}

推荐答案

您似乎真的希望能够解析MediaWiki标记.为此目的设计了一个名为 mwlib 的python库.您可以使用python的内置XML包从API的响应中提取页面内容,然后将该内容传递到mwlib的解析器中以生成对象表示形式,您可以在代码中浏览和分析该对象表示形式以提取所需的信息. mwlib已获得BSD许可.

It looks like you really want to be able to parse MediaWiki markup. There is a python library designed for this purpose called mwlib. You can use python's built-in XML packages to extract the page content from the API's response, then pass that content into mwlib's parser to produce an object representation that you can browse and analyse in code to extract the information you want. mwlib is BSD licensed.

这篇关于解析维基百科转储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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