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