From 940c5638735ca91e09d87016f16d406cdd531ce4 Mon Sep 17 00:00:00 2001 From: sgrtye Date: Fri, 1 Mar 2024 22:26:47 +0000 Subject: [PATCH] add more error message handling --- novel/main.py | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/novel/main.py b/novel/main.py index 3960830..c6b4c11 100644 --- a/novel/main.py +++ b/novel/main.py @@ -130,17 +130,23 @@ def start_health_server(): def get_book_title(url, proxy=None): - html = requests.get( - url, - headers=headers, - proxies=proxy, - ) - html.encoding = "gbk" - tree = etree.HTML(html.text, parser=None) - - div_element = tree.xpath('//div[contains(@class, "qustime")]')[0] - span_element = div_element.xpath("./ul/li[1]/a/span")[0] - return span_element.text + try: + html = requests.get( + url, + headers=headers, + proxies=proxy, + ) + html.encoding = "gbk" + tree = etree.HTML(html.text, parser=None) + + div_element = tree.xpath('//div[contains(@class, "qustime")]')[0] + span_element = div_element.xpath("./ul/li[1]/a/span")[0] + return span_element.text + + except Exception as e: + if proxy is None: + print("The following error occurred when using native ip") + raise e try: