From c0a1bb1517427366d33d51630f6351f34fa7d6d0 Mon Sep 17 00:00:00 2001 From: caiwx86 Date: Thu, 8 Dec 2022 07:55:38 +0800 Subject: [PATCH] fixt --- utils/HtmlUtils.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/utils/HtmlUtils.py b/utils/HtmlUtils.py index baa9e99..147830a 100644 --- a/utils/HtmlUtils.py +++ b/utils/HtmlUtils.py @@ -29,8 +29,6 @@ class htmlUtils: try: print("请求地址:",curl) res = s.get(curl,stream=True, headers=cls.headers, timeout=20) - if type == "json": - url_text = res.json() if type == "bytes": url_text = res else: @@ -55,7 +53,16 @@ class htmlUtils: @classmethod def getJSON(cls,curl): - return cls.getHTML(curl,type="json") + count = 1 + data_json = None + while count < 5: + try: + res = requests.get(curl, headers=cls.headers,timeout=30) + data_json = res.json() + except: + count += 1 + cls.getJSON(curl) + return data_json @classmethod def xpathData(cls,c_xpath,url=None,num=None,not_eq=None):