fix
This commit is contained in:
parent
f5d553a000
commit
44a775a408
@ -57,33 +57,22 @@ class htmlUtils:
|
||||
s = requests.Session()
|
||||
s.mount('http://', HTTPAdapter(max_retries=retries))
|
||||
s.mount('https://', HTTPAdapter(max_retries=retries))
|
||||
count = 1
|
||||
#数据为空则获取数据
|
||||
try: url_text = cls.getPathSaveHtml(curl,"read")
|
||||
except: url_text = None
|
||||
if url_text != None and update == False: return html.fromstring(url_text)
|
||||
else: url_text = None
|
||||
while url_text == None:
|
||||
try:
|
||||
print(f"请求地址:{curl}")
|
||||
res = s.get(curl,stream=True, headers=cls.headers, timeout=10,allow_redirects=True)
|
||||
if type == "bytes":
|
||||
url_text = res
|
||||
if type == "json":
|
||||
#url_text = res.json()
|
||||
try:
|
||||
cls.saveHtml(curl,res.text,type="json")
|
||||
return json.loads(res.text)
|
||||
except:
|
||||
return None
|
||||
if type == None:
|
||||
url_text = html.fromstring(res.text)
|
||||
cls.saveHtml(curl,res.text)
|
||||
except:
|
||||
print(f'Retry! 第{count}次')
|
||||
cls.remove_HtmlCache(curl)
|
||||
time.sleep(1)
|
||||
continue
|
||||
return url_text
|
||||
|
||||
@classmethod
|
||||
|
||||
Loading…
Reference in New Issue
Block a user