From 3338974c1851b2b17dcd3cfa866e4dd65a8130f3 Mon Sep 17 00:00:00 2001 From: khuang6 Date: Sat, 23 Dec 2017 15:21:31 +0800 Subject: [PATCH] fix None Value error of tag_exp --- 2.1/service/oxford_learning.py | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/2.1/service/oxford_learning.py b/2.1/service/oxford_learning.py index df57131..b1cc513 100644 --- a/2.1/service/oxford_learning.py +++ b/2.1/service/oxford_learning.py @@ -116,8 +116,8 @@ def __init__(self, markups): return self.markups = markups self.bs = BeautifulSoup(self.markups) - self._defs = None - self._defs_html = None + self._defs = [] + self._defs_html = [] @staticmethod def _cls_dic(class_nm): @@ -234,21 +234,22 @@ def wd_sound_url_nam(self): return '' def get_definitions(self): + defs = [] + defs_html = [] if not self._defs: - defs = [] - defs_html = [] tag_exp = self._clean(self.tag_explain) - lis = [li for li in tag_exp.find_all('li')] - if not lis: - defs_html.append(str(tag_exp.prettify())) - defs.append(tag_exp.text) - - else: - for li in lis: - defs_html.append(str(li.prettify())) - defs.append(li.text) - self._defs = defs - self._defs_html = defs_html + if tag_exp: + lis = [li for li in tag_exp.find_all('li')] + if not lis: + defs_html.append(str(tag_exp.prettify())) + defs.append(tag_exp.text) + + else: + for li in lis: + defs_html.append(str(li.prettify())) + defs.append(li.text) + self._defs = defs + self._defs_html = defs_html return self._defs, self._defs_html @property