完善_try_to_connect()逻辑

This commit is contained in:
g1879 2021-01-08 11:17:39 +08:00
parent f4e80fdd92
commit 94ab5975a9
2 changed files with 11 additions and 17 deletions

View File

@ -101,20 +101,17 @@ class DriverPage(object):
:return: 是否成功
"""
err = None
def go() -> bool:
nonlocal err
try:
self.driver.get(to_url)
return True
except Exception as e:
err = e
return False
is_ok = False
for _ in range(times + 1):
is_ok = self.check_page() if go() else False
try:
self.driver.get(to_url)
go_ok = True
except Exception as e:
err = e
go_ok = False
is_ok = self.check_page() if go_ok else False
if is_ok is not False:
break

View File

@ -200,16 +200,13 @@ class SessionPage(object):
err = None
r = None
def go() -> Union[Response, None]:
nonlocal err
for _ in range(times + 1):
try:
return self._make_response(to_url, mode=mode, show_errmsg=True, **kwargs)[0]
r = self._make_response(to_url, mode=mode, show_errmsg=True, **kwargs)[0]
except Exception as e:
err = e
return None
r = None
for _ in range(times + 1):
r = go()
if r and (r.content != b'' or r.status_code in (403, 404)):
break