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 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 time import perf_counter, sleep
|
||||
|
||||
from requests import adapters
|
||||
from requests import Session
|
||||
from websocket import (WebSocketTimeoutException, WebSocketConnectionClosedException, create_connection,
|
||||
WebSocketException, WebSocketBadStatusException)
|
||||
@ -17,6 +18,8 @@ from websocket import (WebSocketTimeoutException, WebSocketConnectionClosedExcep
|
||||
from .._functions.settings import Settings
|
||||
from ..errors import PageDisconnectedError, BrowserConnectError
|
||||
|
||||
adapters.DEFAULT_RETRIES = 5
|
||||
|
||||
|
||||
class Driver(object):
|
||||
def __init__(self, tab_id, tab_type, address, owner=None):
|
||||
@ -283,14 +286,15 @@ class BrowserDriver(Driver):
|
||||
self._created = True
|
||||
BrowserDriver.BROWSERS[tab_id] = self
|
||||
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):
|
||||
return f'<BrowserDriver {self.id}>'
|
||||
|
||||
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()
|
||||
s.close()
|
||||
return r
|
||||
|
@ -9,7 +9,7 @@ from queue import Queue
|
||||
from threading import Thread
|
||||
from typing import Union, Callable, Dict, Optional
|
||||
|
||||
from requests import Response, Session
|
||||
from requests import Response
|
||||
from websocket import WebSocket
|
||||
|
||||
from .browser import Chromium
|
||||
@ -69,7 +69,6 @@ class Driver(object):
|
||||
class BrowserDriver(Driver):
|
||||
BROWSERS: Dict[str, Driver] = ...
|
||||
owner: Chromium = ...
|
||||
_control_session: Session = ...
|
||||
|
||||
def __new__(cls, tab_id: str, tab_type: str, address: str, owner: Chromium): ...
|
||||
|
||||
|
@ -164,11 +164,12 @@ class ChromiumElement(DrissionElement):
|
||||
@property
|
||||
def sr(self):
|
||||
"""返回当前元素的shadow_root元素对象"""
|
||||
info = self.owner._run_cdp('DOM.describeNode', backendNodeId=self._backend_id)['node']
|
||||
if not info.get('shadowRoots', None):
|
||||
return None
|
||||
|
||||
return ShadowRoot(self, backend_id=info['shadowRoots'][0]['backendNodeId'])
|
||||
end_time = perf_counter() + self.owner.timeout
|
||||
while perf_counter() < end_time:
|
||||
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 None
|
||||
|
||||
@property
|
||||
def shadow_root(self):
|
||||
|
Loading…
x
Reference in New Issue
Block a user