dictionary.com的一个伪api,通过抓取其网站来工作。
dictcom的Python项目详细描述
dictcom
dictcom是一个简单的python包,通过web抓取从dictionary.com中提取字典信息。它可以被认为是dictionary.com的非正式“api”。
安装
dictcom在pypi上可用:
$ pip install dictcom
目前它只在python 3下工作。使用Python3.4和3.5进行测试。
用法
包本身公开了两个主要方法,get_word和get_word_pronunciation。
get_word下载所提供单词的所有数据,并将其打包成Word对象:
import dictcom word = dictcom.get_word('something') # an instance of dictcom.models.Word
您可以通过pronunciation属性访问单词的发音(它的文本表示形式):
word.pronunciation # '[suhm-thing]'
这些定义作为字典在defs属性下找到。字典的每个键代表一个定义小节,通常表示不同的词性(例如名词或代词):
word.defs.keys() # ['pronoun', 'noun', 'adverb']
每个键下的值是一个Definition实例的列表。每个定义都有两个属性,text和example。
还可以下载单词发音的音频文件:
pronun = word.get_pronunciation_audio() # an instance of dictcom.models.WordPronunciation pronun.audio # raw audio buffer pronun.content_type # the MIME type of the buffer data
您还可以使用get_word_pronunciation立即获得发音音频,该包公开的另一个方法是get_word_pronunciation。