diff --git a/DrissionPage/__init__.py b/DrissionPage/__init__.py index 59ac683..09f8ea7 100644 --- a/DrissionPage/__init__.py +++ b/DrissionPage/__init__.py @@ -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' diff --git a/DrissionPage/_base/driver.py b/DrissionPage/_base/driver.py index 8a75f01..807b648 100644 --- a/DrissionPage/_base/driver.py +++ b/DrissionPage/_base/driver.py @@ -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'' 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 diff --git a/DrissionPage/_base/driver.pyi b/DrissionPage/_base/driver.pyi index be5f7c1..539676d 100644 --- a/DrissionPage/_base/driver.pyi +++ b/DrissionPage/_base/driver.pyi @@ -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): ... diff --git a/DrissionPage/_elements/chromium_element.py b/DrissionPage/_elements/chromium_element.py index 810d1df..e0e40ea 100644 --- a/DrissionPage/_elements/chromium_element.py +++ b/DrissionPage/_elements/chromium_element.py @@ -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):