Add vocabulary.com web dictionary fix #83

This commit is contained in:
sthoo 2018-11-04 13:32:14 +08:00
parent a95dc6af2b
commit b165b2d30d
2 changed files with 76 additions and 0 deletions

View File

@ -0,0 +1,38 @@
#-*- coding:utf-8 -*-
import random
from ..base import *
@register(u'Vocabulary.com')
class Vocabulary(WebService):
def __init__(self):
super(Vocabulary, self).__init__()
def _get_from_api(self):
data = self.get_response(u'https://www.vocabulary.com/dictionary/{}'.format(self.quote_word))
soup = parse_html(data)
result = {
'short': u'',
'long': u'',
}
# short
element = soup.find('p', class_='short')
if element:
result['short'] = u''.join(str(e) for e in element.contents)
# long
element = soup.find('p', class_='long')
if element:
result['long'] = u''.join(str(e) for e in element.contents)
return self.cache_this(result)
@export([u'简短释义', u'Short definition'])
def fld_definate(self):
return self._get_field('short')
@export([u'详细释义', u'Long definition'])
def fld_example(self):
return self._get_field('long')

View File

@ -0,0 +1,38 @@
#-*- coding:utf-8 -*-
import random
from ..base import *
@register(u'Vocabulary.com')
class Vocabulary(WebService):
def __init__(self):
super(Vocabulary, self).__init__()
def _get_from_api(self):
data = self.get_response(u'https://www.vocabulary.com/dictionary/{}'.format(self.quote_word))
soup = parse_html(data)
result = {
'short': u'',
'long': u'',
}
# short
element = soup.find('p', class_='short')
if element:
result['short'] = u''.join(str(e) for e in element.contents)
# long
element = soup.find('p', class_='long')
if element:
result['long'] = u''.join(str(e) for e in element.contents)
return self.cache_this(result)
@export([u'简短释义', u'Short definition'])
def fld_definate(self):
return self._get_field('short')
@export([u'详细释义', u'Long definition'])
def fld_example(self):
return self._get_field('long')