[python]分享一个好用的python的wiki库——Wikipedia API

in #cn6 years ago

最近需要要爬一些维基百科上的内容,试用了好几个python的库,发现了一个特别好用的,整理一下,分享给大家。

一开始用的是wikipedia这个库,但是不知道是我电脑配置问题还是这个库已经不维护了,运行的时候都会被服务器拒绝。

所以转而就试了Wikipedia-API这个库。
https://pypi.org/project/Wikipedia-API/

这是一个打包好了的,用来调取维基百科api的python库,对于要爬维基的朋友来说,非常有用啦~~

简单的翻一下文档,供大家参考:

安装:
pip3 install wikipedia-api

//import:
import wikipediaapi

//选择语言(如果选择中文则将en改为zh)
wiki_wiki = wikipediaapi.Wikipedia('en')

//获取关键词的页面
page_py = wiki_wiki.page(“关键词”)

//确认关键词页面是否存在
page_py .exists()

//获取页面标题
page_py.title

//获取页面概述
page_py.summary

//获取页面上的其他分类信息
page_py.sections

另外这个库还可以查看页面的其他链接、按分类查看等等功能;更具体的可以去库的主页查看:
https://github.com/martin-majlis/Wikipedia-API

Sort:  

你那里天气如何?还在发愁自己的好文没人发现,收益惨淡吗?记得加上cn-curation标签,让飞鸽传书 帮你走出困境吧!假如我的留言打扰到你,请回复“取消”。

Congratulations @littlexiannv! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :

You made more than 500 upvotes. Your next target is to reach 600 upvotes.

Click here to view your Board of Honor
If you no longer want to receive notifications, reply to this comment with the word STOP

Do not miss the last post from @steemitboard:

SteemFest3 and SteemitBoard - Meet the Steemians Contest

Support SteemitBoard's project! Vote for its witness and get one more award!

Congratulations @littlexiannv! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :

You made more than 600 upvotes. Your next target is to reach 700 upvotes.

Click here to view your Board of Honor
If you no longer want to receive notifications, reply to this comment with the word STOP

Do not miss the last post from @steemitboard:

Meet the Steemians Contest - The results, the winners and the prizes
Meet the Steemians Contest - Special attendees revealed
Meet the Steemians Contest - Intermediate results

Support SteemitBoard's project! Vote for its witness and get one more award!

Congratulations @littlexiannv! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :

You made more than 700 upvotes. Your next target is to reach 800 upvotes.

Click here to view your Board of Honor
If you no longer want to receive notifications, reply to this comment with the word STOP

Do not miss the last post from @steemitboard:

Saint Nicholas challenge for good boys and girls

Support SteemitBoard's project! Vote for its witness and get one more award!

Congratulations @littlexiannv! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :

You made more than 800 upvotes. Your next target is to reach 900 upvotes.

Click here to view your Board of Honor
If you no longer want to receive notifications, reply to this comment with the word STOP

Support SteemitBoard's project! Vote for its witness and get one more award!

Congratulations @littlexiannv! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :

You made more than 900 upvotes. Your next target is to reach 1000 upvotes.

Click here to view your Board
If you no longer want to receive notifications, reply to this comment with the word STOP

Support SteemitBoard's project! Vote for its witness and get one more award!

Congratulations @littlexiannv! You received a personal award!

Happy Birthday! - You are on the Steem blockchain for 1 year!

You can view your badges on your Steem Board and compare to others on the Steem Ranking

Vote for @Steemitboard as a witness to get one more award and increased upvotes!