From cfd3d39ee73a362e9a5538a61ab1815f5ff91552 Mon Sep 17 00:00:00 2001 From: calmzeal <76763831@qq.com> Date: Sat, 5 May 2018 19:23:43 +0800 Subject: [PATCH] fix empty elem in get_elem_text (#197) --- wechatsogou/tools.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/wechatsogou/tools.py b/wechatsogou/tools.py index 0aa9923..dc7b742 100644 --- a/wechatsogou/tools.py +++ b/wechatsogou/tools.py @@ -37,7 +37,10 @@ def get_elem_text(elem): Returns: elem中文字 """ - return ''.join([node.strip() for node in elem.itertext()]) + if elem != '': + return ''.join([node.strip() for node in elem.itertext()]) + else: + return '' def get_first_of_element(element, sub, contype=None):