mirror of
https://gitee.com/g1879/DrissionPage.git
synced 2024-12-10 04:00:23 +08:00
页面类添加retry_times和retry_interval属性
This commit is contained in:
parent
48049e4b03
commit
51cef7fa7f
@ -30,6 +30,9 @@ class DriverPage(object):
|
||||
self._url_available = None
|
||||
self._wait = None
|
||||
|
||||
self.retry_times = 3
|
||||
self.retry_interval = 2
|
||||
|
||||
@property
|
||||
def driver(self) -> WebDriver:
|
||||
return self._driver
|
||||
@ -99,22 +102,24 @@ class DriverPage(object):
|
||||
"""
|
||||
self.driver.get(to_url)
|
||||
is_ok = self.check_page()
|
||||
|
||||
while times and is_ok is False:
|
||||
sleep(interval)
|
||||
self.driver.get(to_url)
|
||||
is_ok = self.check_page()
|
||||
times -= 1
|
||||
|
||||
if is_ok is False and show_errmsg:
|
||||
raise ConnectionError('Connect error.')
|
||||
|
||||
return is_ok
|
||||
|
||||
def get(self,
|
||||
url: str,
|
||||
go_anyway: bool = False,
|
||||
show_errmsg: bool = False,
|
||||
retry: int = 0,
|
||||
interval: float = 1,
|
||||
) -> Union[None, bool]:
|
||||
retry: int = None,
|
||||
interval: float = None) -> Union[None, bool]:
|
||||
"""访问url \n
|
||||
:param url: 目标url
|
||||
:param go_anyway: 若目标url与当前url一致,是否强制跳转
|
||||
@ -124,10 +129,15 @@ class DriverPage(object):
|
||||
:return: 目标url是否可用
|
||||
"""
|
||||
to_url = quote(url, safe='/:&?=%;#@')
|
||||
retry = int(retry) if retry is not None else int(self.retry_times)
|
||||
interval = int(interval) if interval is not None else int(self.retry_interval)
|
||||
|
||||
if not url or (not go_anyway and self.url == to_url):
|
||||
return
|
||||
|
||||
self._url = to_url
|
||||
self._url_available = self._try_to_connect(to_url, times=retry, interval=interval, show_errmsg=show_errmsg)
|
||||
|
||||
return self._url_available
|
||||
|
||||
def ele(self,
|
||||
|
@ -58,6 +58,9 @@ class MixPage(Null, SessionPage, DriverPage):
|
||||
self._url_available = None
|
||||
self._mode = mode
|
||||
|
||||
self.retry_times = 3
|
||||
self.retry_interval = 2
|
||||
|
||||
if mode == 's':
|
||||
self._driver = None
|
||||
self._session = True
|
||||
@ -236,8 +239,8 @@ class MixPage(Null, SessionPage, DriverPage):
|
||||
data: dict = None,
|
||||
go_anyway: bool = False,
|
||||
show_errmsg: bool = False,
|
||||
retry: int = 2,
|
||||
interval: float = 1,
|
||||
retry: int = None,
|
||||
interval: float = None,
|
||||
**kwargs) -> Union[bool, None]:
|
||||
"""用post方式跳转到url,会切换到s模式 \n
|
||||
:param url: 目标url
|
||||
@ -319,8 +322,8 @@ class MixPage(Null, SessionPage, DriverPage):
|
||||
url: str,
|
||||
go_anyway=False,
|
||||
show_errmsg: bool = False,
|
||||
retry: int = 2,
|
||||
interval: float = 1,
|
||||
retry: int = None,
|
||||
interval: float = None,
|
||||
**kwargs) -> Union[bool, None]:
|
||||
"""跳转到一个url \n
|
||||
跳转前先同步cookies,跳转后判断目标url是否可用
|
||||
|
@ -33,6 +33,9 @@ class SessionPage(object):
|
||||
self._url_available = None
|
||||
self._response = None
|
||||
|
||||
self.retry_times = 3
|
||||
self.retry_interval = 2
|
||||
|
||||
@property
|
||||
def session(self) -> Session:
|
||||
"""返回session对象"""
|
||||
@ -212,8 +215,8 @@ class SessionPage(object):
|
||||
url: str,
|
||||
go_anyway: bool = False,
|
||||
show_errmsg: bool = False,
|
||||
retry: int = 0,
|
||||
interval: float = 1,
|
||||
retry: int = None,
|
||||
interval: float = None,
|
||||
**kwargs) -> Union[bool, None]:
|
||||
"""用get方式跳转到url \n
|
||||
:param url: 目标url
|
||||
@ -225,6 +228,8 @@ class SessionPage(object):
|
||||
:return: url是否可用
|
||||
"""
|
||||
to_url = quote(url, safe='/:&?=%;#@+')
|
||||
retry = int(retry) if retry is not None else int(self.retry_times)
|
||||
interval = int(interval) if interval is not None else int(self.retry_interval)
|
||||
|
||||
if not url or (not go_anyway and self.url == to_url):
|
||||
return
|
||||
@ -252,8 +257,8 @@ class SessionPage(object):
|
||||
data: dict = None,
|
||||
go_anyway: bool = True,
|
||||
show_errmsg: bool = False,
|
||||
retry: int = 0,
|
||||
interval: float = 1,
|
||||
retry: int = None,
|
||||
interval: float = None,
|
||||
**kwargs) -> Union[bool, None]:
|
||||
"""用post方式跳转到url \n
|
||||
:param url: 目标url
|
||||
@ -266,6 +271,8 @@ class SessionPage(object):
|
||||
:return: url是否可用
|
||||
"""
|
||||
to_url = quote(url, safe='/:&?=%;#@')
|
||||
retry = int(retry) if retry is not None else int(self.retry_times)
|
||||
interval = int(interval) if interval is not None else int(self.retry_interval)
|
||||
|
||||
if not url or (not go_anyway and self._url == to_url):
|
||||
return
|
||||
|
Loading…
x
Reference in New Issue
Block a user