用于python的wikipedia api
wikipedia的Python项目详细描述
wikipedia是一个易于访问和解析的python库 维基百科的数据。
搜索维基百科,获取文章摘要,获取链接和图片等数据 从一页,等等。维基百科将MediaWiki API包装起来,这样您就可以专注于使用 维基百科的数据,不知道。
>>>importwikipedia>>>printwikipedia.summary("Wikipedia")# Wikipedia (/ˌwɪkɨˈpiːdiə/ or /ˌwɪkiˈpiːdiə/ WIK-i-PEE-dee-ə) is a collaboratively edited, multilingual, free Internet encyclopedia supported by the non-profit Wikimedia Foundation...>>>wikipedia.search("Barack")# [u'Barak (given name)', u'Barack Obama', u'Barack (brandy)', u'Presidency of Barack Obama', u'Family of Barack Obama', u'First inauguration of Barack Obama', u'Barack Obama presidential campaign, 2008', u'Barack Obama, Sr.', u'Barack Obama citizenship conspiracy theories', u'Presidential transition of Barack Obama']>>>ny=wikipedia.page("New York")>>>ny.title# u'New York'>>>ny.url# u'http://en.wikipedia.org/wiki/New_York'>>>ny.content# u'New York is a state in the Northeastern region of the United States. New York is the 27th-most exten'...>>>ny.links[0]# u'1790 United States Census'>>>wikipedia.set_lang("fr")>>>wikipedia.summary("Facebook",sentences=1)# Facebook est un service de réseautage social en ligne sur Internet permettant d'y publier des informations (photographies, liens, textes, etc.) en contrôlant leur visibilité par différentes catégories de personnes.
注意:这个库是为简单易用而设计的,不是为高级使用而设计的。如果您计划执行严重的刮擦或自动请求,请使用Pywikipediabot(或其他更高级的Python MediaWiki API wrappers),它具有更大的api、速率限制和其他功能,因此我们可以考虑mediawiki基础设施。
安装
要安装Wikipedia,只需运行:
$ pip install wikipedia
wikipedia与python 2.6+(运行unittest discover的是2.7+)和python 3.3+兼容。
文档
阅读https://wikipedia.readthedocs.org/en/latest/上的文档。
要运行测试,请克隆respository on GitHub,然后运行:
$ pip install -r requirements.txt $ bash runtests # will run tests for python and python3 $ python -m unittest discover tests/ '*test.py' # manual style
在根项目目录中。
要自行构建文档,请在安装requirements.txt之后运行:
$ pip install sphinx $ cd docs/ $ make html
许可证
麻省理工学院许可。参见LICENSE file了解 全部细节。