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