From 368538e980d75853213adceb03a75e442a4c23fa Mon Sep 17 00:00:00 2001 From: caiwx86 Date: Mon, 9 Jan 2023 20:24:08 +0800 Subject: [PATCH] fix --- utils/HtmlUtils.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/utils/HtmlUtils.py b/utils/HtmlUtils.py index d929d9b..40bd7a7 100644 --- a/utils/HtmlUtils.py +++ b/utils/HtmlUtils.py @@ -68,6 +68,9 @@ class htmlUtils: try: print(f"请求地址:{curl}") res = s.get(curl,stream=True, headers=cls.headers, timeout=180,allow_redirects=True) + if res.status_code != 200: + cls.remove_HtmlCache(curl) + return None if type == "bytes": url_text = res if type == "json": @@ -77,8 +80,6 @@ class htmlUtils: if type == None: url_text = html.fromstring(res.text) cls.saveHtml(curl,res.text) - if res.status_code != 200: - cls.remove_HtmlCache(curl) except: print(f'Retry! 第{count}次') time.sleep(1) @@ -97,12 +98,13 @@ class htmlUtils: @classmethod def getJSON(cls,url): - url_text = requests.get(url,headers=cls.headers, timeout=180).text + res = requests.get(url,headers=cls.headers, timeout=180) + if res.status_code != 200: + return None try: - return json.loads(url_text) + return json.loads(res.text) except: return None - #return cls.getHTML(url,type="json") @classmethod def xpathData(cls,c_xpath,url=None,num=None,not_eq=None,update=False):