From 26c892386e073bf563f7b621c216ecdbf6f7575a Mon Sep 17 00:00:00 2001 From: ZouJiu <1069679911@qq.com> Date: Fri, 28 Jul 2023 20:38:18 +0800 Subject: [PATCH] words in bolden --- crawler.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/crawler.py b/crawler.py index bb3e77a..6564588 100644 --- a/crawler.py +++ b/crawler.py @@ -363,13 +363,15 @@ def recursion(nod, article, number, driver, dircrea, bk=False): else: article += "["+nod.text+"]"+"("+linksite + ")" elif tag_name=="b" or tag_name=="strong": - p_childNodes = driver.execute_script("return arguments[0].childNodes;", nod) - for pnode in p_childNodes: - article, number = recursion(pnode, article, number, driver, dircrea, True) - # txt = nod.text - # while len(txt) > 0 and txt[-1] == " ": - # txt = txt[:-1] - # article += " **" + txt + "** " + try: + p_childNodes = driver.execute_script("return arguments[0].childNodes;", nod) + for pnode in p_childNodes: + article, number = recursion(pnode, article, number, driver, dircrea, True) + except: + txt = nod.text + while len(txt) > 0 and txt[-1] == " ": + txt = txt[:-1] + article += " **" + txt + "** " elif tag_name=="em": if bk: article += "**"