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):