mirror of
https://gitee.com/g1879/DrissionPage.git
synced 2024-12-10 04:00:23 +08:00
4.1.0.0b18 sr自动等待
This commit is contained in:
parent
cae2151795
commit
1c54f59feb
@ -14,4 +14,4 @@ from ._pages.chromium_page import ChromiumPage
|
|||||||
from ._pages.mix_page import MixPage
|
from ._pages.mix_page import MixPage
|
||||||
from ._pages.mix_page import MixPage as WebPage
|
from ._pages.mix_page import MixPage as WebPage
|
||||||
|
|
||||||
__version__ = '4.1.0.0b17'
|
__version__ = '4.1.0.0b18'
|
||||||
|
@ -10,6 +10,7 @@ from queue import Queue, Empty
|
|||||||
from threading import Thread
|
from threading import Thread
|
||||||
from time import perf_counter, sleep
|
from time import perf_counter, sleep
|
||||||
|
|
||||||
|
from requests import adapters
|
||||||
from requests import Session
|
from requests import Session
|
||||||
from websocket import (WebSocketTimeoutException, WebSocketConnectionClosedException, create_connection,
|
from websocket import (WebSocketTimeoutException, WebSocketConnectionClosedException, create_connection,
|
||||||
WebSocketException, WebSocketBadStatusException)
|
WebSocketException, WebSocketBadStatusException)
|
||||||
@ -17,6 +18,8 @@ from websocket import (WebSocketTimeoutException, WebSocketConnectionClosedExcep
|
|||||||
from .._functions.settings import Settings
|
from .._functions.settings import Settings
|
||||||
from ..errors import PageDisconnectedError, BrowserConnectError
|
from ..errors import PageDisconnectedError, BrowserConnectError
|
||||||
|
|
||||||
|
adapters.DEFAULT_RETRIES = 5
|
||||||
|
|
||||||
|
|
||||||
class Driver(object):
|
class Driver(object):
|
||||||
def __init__(self, tab_id, tab_type, address, owner=None):
|
def __init__(self, tab_id, tab_type, address, owner=None):
|
||||||
@ -283,14 +286,15 @@ class BrowserDriver(Driver):
|
|||||||
self._created = True
|
self._created = True
|
||||||
BrowserDriver.BROWSERS[tab_id] = self
|
BrowserDriver.BROWSERS[tab_id] = self
|
||||||
super().__init__(tab_id, tab_type, address, owner)
|
super().__init__(tab_id, tab_type, address, owner)
|
||||||
self._control_session = Session()
|
|
||||||
self._control_session.trust_env = False
|
|
||||||
self._control_session.keep_alive = False
|
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f'<BrowserDriver {self.id}>'
|
return f'<BrowserDriver {self.id}>'
|
||||||
|
|
||||||
def get(self, url):
|
def get(self, url):
|
||||||
r = self._control_session.get(url, headers={'Connection': 'close'})
|
s = Session()
|
||||||
|
s.trust_env = False
|
||||||
|
s.keep_alive = False
|
||||||
|
r = s.get(url, headers={'Connection': 'close'})
|
||||||
r.close()
|
r.close()
|
||||||
|
s.close()
|
||||||
return r
|
return r
|
||||||
|
@ -9,7 +9,7 @@ from queue import Queue
|
|||||||
from threading import Thread
|
from threading import Thread
|
||||||
from typing import Union, Callable, Dict, Optional
|
from typing import Union, Callable, Dict, Optional
|
||||||
|
|
||||||
from requests import Response, Session
|
from requests import Response
|
||||||
from websocket import WebSocket
|
from websocket import WebSocket
|
||||||
|
|
||||||
from .browser import Chromium
|
from .browser import Chromium
|
||||||
@ -69,7 +69,6 @@ class Driver(object):
|
|||||||
class BrowserDriver(Driver):
|
class BrowserDriver(Driver):
|
||||||
BROWSERS: Dict[str, Driver] = ...
|
BROWSERS: Dict[str, Driver] = ...
|
||||||
owner: Chromium = ...
|
owner: Chromium = ...
|
||||||
_control_session: Session = ...
|
|
||||||
|
|
||||||
def __new__(cls, tab_id: str, tab_type: str, address: str, owner: Chromium): ...
|
def __new__(cls, tab_id: str, tab_type: str, address: str, owner: Chromium): ...
|
||||||
|
|
||||||
|
@ -164,11 +164,12 @@ class ChromiumElement(DrissionElement):
|
|||||||
@property
|
@property
|
||||||
def sr(self):
|
def sr(self):
|
||||||
"""返回当前元素的shadow_root元素对象"""
|
"""返回当前元素的shadow_root元素对象"""
|
||||||
info = self.owner._run_cdp('DOM.describeNode', backendNodeId=self._backend_id)['node']
|
end_time = perf_counter() + self.owner.timeout
|
||||||
if not info.get('shadowRoots', None):
|
while perf_counter() < end_time:
|
||||||
return None
|
info = self.owner._run_cdp('DOM.describeNode', backendNodeId=self._backend_id)['node']
|
||||||
|
if info.get('shadowRoots', None):
|
||||||
return ShadowRoot(self, backend_id=info['shadowRoots'][0]['backendNodeId'])
|
return ShadowRoot(self, backend_id=info['shadowRoots'][0]['backendNodeId'])
|
||||||
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def shadow_root(self):
|
def shadow_root(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user