#-*- coding:utf-8 -*- import os from ..base import * cambridge_download_mp3 = True @register([u'剑桥英英', u'Cambridge']) class Cambridge(WebService): def __init__(self): super(Cambridge, self).__init__() def _get_from_api(self): data = self.get_response(u"https://dictionary.cambridge.org/dictionary/english/{}".format(self.quote_word)) soup = parse_html(data) result = { 'pronunciation': {'AmE': '', 'BrE': '', 'AmEmp3': '', 'BrEmp3': ''}, 'def': '', 'sams': '', } #页 element = soup.find('div', class_='entry-body__el clrd js-share-holder') if element: #音 header = element.find('div', class_='pos-header') if header: tags = header.find_all('span', class_='pron-info') if tags: for tag in tags: r = tag.find('span', class_='region') reg = str(r.get_text()).decode('utf-8') if r else u'' pn = 'AmE' if reg=='us' else 'BrE' p = tag.find('span', class_='pron') result['pronunciation'][pn] = str(p.get_text()).decode('utf-8') if p else u'' snd = tag.find('span', class_='circle circle-btn sound audio_play_button') if snd: result['pronunciation'][pn+'mp3'] = u'https://dictionary.cambridge.org' + snd.get('data-src-mp3') #义 body = element.find('div', class_='pos-body') if body: tags = body.find_all('div', class_='def-block pad-indent') if tags: l = [] for tag in tags: i = tag.find('span', class_='def-info') d = tag.find('b', class_='def') e = tag.find('div', class_='examp emphasized') l.append( u'