Python维基百科API
项目描述
维基百科 是一个Python库,它使得访问和解析来自维基百科的数据变得容易。
搜索维基百科,获取文章摘要,从页面获取数据如链接和图片等。维基百科封装了 MediaWiki API,这样你可以专注于使用维基百科数据,而不是获取数据。
>>> import wikipedia
>>> print wikipedia.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封装器),它具有更大的API、速率限制和其他功能,以便我们能够考虑到MediaWiki基础设施。
安装
要安装维基百科,只需运行
$ pip install wikipedia
维基百科与Python 2.6+(2.7+用于运行unittest discover)和Python 3.3+兼容。
文档
阅读https://wikipedia.readthedocs.org/en/latest/上的文档。
要运行测试,克隆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
许可证
MIT许可。有关完整详情,请参阅LICENSE文件。
鸣谢
项目详情
关闭
wikipedia-1.4.0.tar.gz 的散列
算法 | 散列摘要 | |
---|---|---|
SHA256 | db0fad1829fdd441b1852306e9856398204dc0786d2996dd2e0c8bb8e26133b2 |
|
MD5 | 898944eb28062d898d3d0d948fdd3fec |
|
BLAKE2b-256 | 673525e68fbc99e672127cc6fbb14b8ec1ba3dfef035bf1e4c90f78f24a80b7d |