mirror of
https://gitee.com/g1879/DrissionPage.git
synced 2024-12-10 04:00:23 +08:00
Browser改名为Chromium
This commit is contained in:
parent
89af82dc2f
commit
7fdd976854
@ -5,7 +5,7 @@
|
||||
@Copyright: (c) 2024 by g1879, Inc. All Rights Reserved.
|
||||
@License : BSD 3-Clause.
|
||||
"""
|
||||
from ._base.browser import Browser
|
||||
from ._base.browser import Chromium
|
||||
from ._configs.chromium_options import ChromiumOptions
|
||||
from ._configs.session_options import SessionOptions
|
||||
# 即将废弃
|
||||
|
@ -5,7 +5,7 @@
|
||||
@Copyright: (c) 2024 by g1879, Inc. All Rights Reserved.
|
||||
@License : BSD 3-Clause.
|
||||
"""
|
||||
from ._base.browser import Browser
|
||||
from ._base.browser import Chromium
|
||||
from ._configs.chromium_options import ChromiumOptions
|
||||
from ._configs.session_options import SessionOptions
|
||||
from ._pages.session_page import SessionPage
|
||||
@ -13,5 +13,5 @@ from ._pages.session_page import SessionPage
|
||||
from ._pages.chromium_page import ChromiumPage
|
||||
from ._pages.web_page import WebPage
|
||||
|
||||
__all__ = ['WebPage', 'ChromiumPage', 'Browser', 'ChromiumOptions', 'SessionOptions', 'SessionPage', '__version__']
|
||||
__all__ = ['WebPage', 'ChromiumPage', 'Chromium', 'ChromiumOptions', 'SessionOptions', 'SessionPage', '__version__']
|
||||
__version__: str = ...
|
||||
|
@ -32,7 +32,7 @@ from ..errors import PageDisconnectedError
|
||||
__ERROR__ = 'error'
|
||||
|
||||
|
||||
class Browser(object):
|
||||
class Chromium(object):
|
||||
_BROWSERS = {}
|
||||
|
||||
def __new__(cls, addr_or_opts=None, session_options=None):
|
||||
@ -61,7 +61,7 @@ class Browser(object):
|
||||
return
|
||||
self._created = True
|
||||
|
||||
self._type = 'Browser'
|
||||
self._type = 'Chromium'
|
||||
|
||||
self._frames = {}
|
||||
self._drivers = {}
|
||||
@ -491,7 +491,7 @@ class Browser(object):
|
||||
return r if __ERROR__ not in r else raise_error(r, ignore)
|
||||
|
||||
def _on_disconnect(self):
|
||||
Browser._BROWSERS.pop(self.id, None)
|
||||
Chromium._BROWSERS.pop(self.id, None)
|
||||
if self._chromium_options.is_auto_port and self._chromium_options.user_data_path:
|
||||
path = Path(self._chromium_options.user_data_path)
|
||||
end_time = perf_counter() + 7
|
||||
|
@ -19,7 +19,7 @@ from .._units.setter import BrowserSetter
|
||||
from .._units.waiter import BrowserWaiter
|
||||
|
||||
|
||||
class Browser(object):
|
||||
class Chromium(object):
|
||||
id: str = ...
|
||||
address: str = ...
|
||||
version: str = ...
|
||||
|
@ -12,7 +12,7 @@ from typing import Union, Callable, Dict, Optional
|
||||
from requests import Response, Session
|
||||
from websocket import WebSocket
|
||||
|
||||
from .browser import Browser
|
||||
from .browser import Chromium
|
||||
|
||||
|
||||
class GenericAttr(object):
|
||||
@ -67,11 +67,11 @@ class Driver(object):
|
||||
|
||||
class BrowserDriver(Driver):
|
||||
BROWSERS: Dict[str, Driver] = ...
|
||||
owner: Browser = ...
|
||||
owner: Chromium = ...
|
||||
_control_session: Session = ...
|
||||
|
||||
def __new__(cls, tab_id: str, tab_type: str, address: str, owner: Browser): ...
|
||||
def __new__(cls, tab_id: str, tab_type: str, address: str, owner: Chromium): ...
|
||||
|
||||
def __init__(self, tab_id: str, tab_type: str, address: str, owner: Browser): ...
|
||||
def __init__(self, tab_id: str, tab_type: str, address: str, owner: Chromium): ...
|
||||
|
||||
def get(self, url) -> Response: ...
|
||||
|
@ -11,7 +11,7 @@ from typing import Union
|
||||
from requests import Session
|
||||
from requests.cookies import RequestsCookieJar
|
||||
|
||||
from .._base.browser import Browser
|
||||
from .._base.browser import Chromium
|
||||
from .._pages.chromium_base import ChromiumBase
|
||||
|
||||
|
||||
@ -24,7 +24,7 @@ def cookies_to_tuple(cookies: Union[RequestsCookieJar, list, tuple, str, dict, C
|
||||
def set_session_cookies(session: Session, cookies: Union[RequestsCookieJar, list, tuple, str, dict]) -> None: ...
|
||||
|
||||
|
||||
def set_browser_cookies(browser: Browser, cookies: Union[RequestsCookieJar, list, tuple, str, dict]) -> None: ...
|
||||
def set_browser_cookies(browser: Chromium, cookies: Union[RequestsCookieJar, list, tuple, str, dict]) -> None: ...
|
||||
|
||||
|
||||
def set_tab_cookies(page: ChromiumBase, cookies: Union[RequestsCookieJar, list, tuple, str, dict]) -> None: ...
|
||||
|
@ -346,7 +346,9 @@ def format_headers(txt):
|
||||
:param txt: 从浏览器复制的原始文本格式headers
|
||||
:return: dict格式headers
|
||||
"""
|
||||
if not isinstance(txt, str):
|
||||
if isinstance(txt, dict):
|
||||
for k, v in txt.items():
|
||||
txt[k] = str(v)
|
||||
return txt
|
||||
headers = {}
|
||||
for header in txt.split('\n'):
|
||||
|
@ -41,7 +41,7 @@ class ChromiumBase(BasePage):
|
||||
|
||||
def __init__(self, browser, tab_id=None):
|
||||
"""
|
||||
:param browser: Browser
|
||||
:param browser: Chromium
|
||||
:param tab_id: 要控制的标签页id,不指定默认为激活的
|
||||
"""
|
||||
super().__init__()
|
||||
|
@ -10,7 +10,7 @@ from typing import Union, Tuple, List, Any, Optional, Literal
|
||||
|
||||
from .chromium_tab import ChromiumTab, MixTab
|
||||
from .._base.base import BasePage
|
||||
from .._base.browser import Browser
|
||||
from .._base.browser import Chromium
|
||||
from .._base.driver import Driver
|
||||
from .._elements.chromium_element import ChromiumElement
|
||||
from .._elements.session_element import SessionElement
|
||||
@ -32,10 +32,10 @@ PIC_TYPE = Literal['jpg', 'jpeg', 'png', 'webp', True]
|
||||
|
||||
class ChromiumBase(BasePage):
|
||||
def __init__(self,
|
||||
browser: Browser,
|
||||
browser: Chromium,
|
||||
tab_id: str = None):
|
||||
self._tab: Union[ChromiumTab, MixTab, ChromiumFrame] = ...
|
||||
self._browser: Browser = ...
|
||||
self._browser: Chromium = ...
|
||||
self._driver: Driver = ...
|
||||
self._frame_id: str = ...
|
||||
self._is_reading: bool = ...
|
||||
@ -102,7 +102,7 @@ class ChromiumBase(BasePage):
|
||||
def _js_ready_state(self) -> str: ...
|
||||
|
||||
@property
|
||||
def browser(self) -> Browser: ...
|
||||
def browser(self) -> Chromium: ...
|
||||
|
||||
@property
|
||||
def title(self) -> str: ...
|
||||
|
@ -7,7 +7,7 @@
|
||||
"""
|
||||
from time import sleep
|
||||
|
||||
from .._base.browser import Browser
|
||||
from .._base.browser import Chromium
|
||||
from .._functions.web import save_page
|
||||
from .._pages.chromium_base import ChromiumBase
|
||||
from .._units.setter import ChromiumPageSetter
|
||||
@ -24,7 +24,7 @@ class ChromiumPage(ChromiumBase):
|
||||
:param tab_id: 要控制的标签页id,不指定默认为激活的
|
||||
:param timeout: 超时时间(秒)
|
||||
"""
|
||||
browser = Browser(addr_or_opts=addr_or_opts)
|
||||
browser = Chromium(addr_or_opts=addr_or_opts)
|
||||
if browser.id in cls._PAGES:
|
||||
r = cls._PAGES[browser.id]
|
||||
while not hasattr(r, '_frame_id'):
|
||||
|
@ -8,7 +8,7 @@
|
||||
from pathlib import Path
|
||||
from typing import Union, Tuple, List, Optional
|
||||
|
||||
from .._base.browser import Browser
|
||||
from .._base.browser import Chromium
|
||||
from .._configs.chromium_options import ChromiumOptions
|
||||
from .._pages.chromium_base import ChromiumBase
|
||||
from .._pages.chromium_tab import ChromiumTab
|
||||
@ -20,7 +20,7 @@ from .._units.waiter import PageWaiter
|
||||
class ChromiumPage(ChromiumBase):
|
||||
_PAGES: dict = ...
|
||||
tab: ChromiumPage = ...
|
||||
_browser: Browser = ...
|
||||
_browser: Chromium = ...
|
||||
_rect: Optional[TabRect] = ...
|
||||
_is_exist: bool = ...
|
||||
|
||||
@ -41,7 +41,7 @@ class ChromiumPage(ChromiumBase):
|
||||
def _page_init(self) -> None: ...
|
||||
|
||||
@property
|
||||
def browser(self) -> Browser: ...
|
||||
def browser(self) -> Chromium: ...
|
||||
|
||||
@property
|
||||
def tabs_count(self) -> int: ...
|
||||
|
@ -52,6 +52,7 @@ class ChromiumTab(ChromiumBase):
|
||||
|
||||
def _d_set_runtime_settings(self):
|
||||
"""重写设置浏览器运行参数方法"""
|
||||
print('a')
|
||||
self._timeouts = copy(self.browser.timeouts)
|
||||
self.retry_times = self.browser.retry_times
|
||||
self.retry_interval = self.browser.retry_interval
|
||||
@ -96,7 +97,7 @@ class ChromiumTab(ChromiumBase):
|
||||
class MixTab(SessionPage, ChromiumTab, BasePage):
|
||||
def __init__(self, browser, tab_id):
|
||||
"""
|
||||
:param browser: Browser对象
|
||||
:param browser: Chromium对象
|
||||
:param tab_id: 标签页id
|
||||
"""
|
||||
if Settings.singleton_tab_obj and hasattr(self, '_created'):
|
||||
|
@ -13,7 +13,7 @@ from requests import Session, Response
|
||||
from .chromium_base import ChromiumBase
|
||||
from .chromium_frame import ChromiumFrame
|
||||
from .session_page import SessionPage
|
||||
from .._base.browser import Browser
|
||||
from .._base.browser import Chromium
|
||||
from .._elements.chromium_element import ChromiumElement
|
||||
from .._elements.session_element import SessionElement
|
||||
from .._functions.cookies import CookiesList
|
||||
@ -26,9 +26,9 @@ from .._units.waiter import TabWaiter
|
||||
class ChromiumTab(ChromiumBase):
|
||||
_TABS: dict = ...
|
||||
|
||||
def __new__(cls, browser: Browser, tab_id: str): ...
|
||||
def __new__(cls, browser: Chromium, tab_id: str): ...
|
||||
|
||||
def __init__(self, browser: Browser, tab_id: str):
|
||||
def __init__(self, browser: Chromium, tab_id: str):
|
||||
self._tab: ChromiumTab = ...
|
||||
self._rect: Optional[TabRect] = ...
|
||||
|
||||
@ -70,7 +70,7 @@ class MixTab(SessionPage, ChromiumTab):
|
||||
_has_driver: bool = ...
|
||||
_has_session: bool = ...
|
||||
|
||||
def __init__(self, browser: Browser, tab_id: str): ...
|
||||
def __init__(self, browser: Chromium, tab_id: str): ...
|
||||
|
||||
def __call__(self,
|
||||
locator: Union[Tuple[str, str], str, ChromiumElement, SessionElement],
|
||||
|
@ -8,7 +8,7 @@
|
||||
from http.cookiejar import Cookie, CookieJar
|
||||
from typing import Union
|
||||
|
||||
from .._base.browser import Browser
|
||||
from .._base.browser import Chromium
|
||||
from .._pages.chromium_base import ChromiumBase
|
||||
from .._pages.chromium_tab import MixTab
|
||||
from .._pages.session_page import SessionPage
|
||||
@ -28,9 +28,9 @@ class CookiesSetter(object):
|
||||
|
||||
|
||||
class BrowserCookiesSetter(CookiesSetter):
|
||||
_owner: Browser = ...
|
||||
_owner: Chromium = ...
|
||||
|
||||
def __init__(self, page: Browser): ...
|
||||
def __init__(self, page: Chromium): ...
|
||||
|
||||
|
||||
class SessionCookiesSetter(object):
|
||||
|
@ -7,13 +7,13 @@
|
||||
"""
|
||||
from typing import Dict, Optional, Union, Literal
|
||||
|
||||
from .._base.browser import Browser
|
||||
from .._base.browser import Chromium
|
||||
from .._pages.chromium_base import ChromiumBase
|
||||
# from .._pages.chromium_page import ChromiumPage
|
||||
FILE_EXISTS = Literal['skip', 'rename', 'overwrite', 's', 'r', 'o']
|
||||
|
||||
class DownloadManager(object):
|
||||
_browser: Browser = ...
|
||||
_browser: Chromium = ...
|
||||
# _page: ChromiumPage = ...
|
||||
_missions: Dict[str, DownloadMission] = ...
|
||||
_tab_missions: dict = ...
|
||||
@ -21,7 +21,7 @@ class DownloadManager(object):
|
||||
_running: bool = ...
|
||||
# _save_path: Optional[str] = ...
|
||||
|
||||
def __init__(self, browser: Browser): ...
|
||||
def __init__(self, browser: Chromium): ...
|
||||
|
||||
@property
|
||||
def missions(self) -> Dict[str, DownloadMission]: ...
|
||||
|
@ -14,7 +14,7 @@ from requests.auth import HTTPBasicAuth
|
||||
from .cookies_setter import SessionCookiesSetter, CookiesSetter, WebPageCookiesSetter, BrowserCookiesSetter
|
||||
from .scroller import PageScroller
|
||||
from .._base.base import BasePage
|
||||
from .._base.browser import Browser
|
||||
from .._base.browser import Chromium
|
||||
from .._elements.chromium_element import ChromiumElement
|
||||
from .._pages.chromium_base import ChromiumBase
|
||||
from .._pages.chromium_frame import ChromiumFrame
|
||||
@ -27,8 +27,8 @@ FILE_EXISTS = Literal['skip', 'rename', 'overwrite', 's', 'r', 'o']
|
||||
|
||||
|
||||
class BasePageSetter(object):
|
||||
def __init__(self, owner: Union[Browser, BasePage]):
|
||||
self._owner: Union[Browser, BasePage] = ...
|
||||
def __init__(self, owner: Union[Chromium, BasePage]):
|
||||
self._owner: Union[Chromium, BasePage] = ...
|
||||
|
||||
def NoneElement_value(self, value: Any = None, on_off: bool = True) -> None: ...
|
||||
|
||||
@ -48,8 +48,8 @@ class BrowserBaseSetter(BasePageSetter):
|
||||
def timeouts(self, base=None, page_load=None, script=None) -> None: ...
|
||||
|
||||
|
||||
class BrowserSetter(BasePageSetter):
|
||||
_owner: Browser = ...
|
||||
class BrowserSetter(BrowserBaseSetter):
|
||||
_owner: Chromium = ...
|
||||
_cookies_setter: BrowserCookiesSetter = ...
|
||||
|
||||
def tab_to_front(self, tab_or_id: Union[str, ChromiumTab]) -> None: ...
|
||||
@ -221,9 +221,9 @@ class ChromiumFrameSetter(ChromiumBaseSetter):
|
||||
|
||||
|
||||
class LoadMode(object):
|
||||
_owner: Union[Browser, ChromiumBase] = ...
|
||||
_owner: Union[Chromium, ChromiumBase] = ...
|
||||
|
||||
def __init__(self, owner: Union[Browser, ChromiumBase]): ...
|
||||
def __init__(self, owner: Union[Chromium, ChromiumBase]): ...
|
||||
|
||||
def __call__(self, value: str) -> None: ...
|
||||
|
||||
|
@ -8,7 +8,7 @@
|
||||
from typing import Union, Tuple, Literal, List
|
||||
|
||||
from .downloader import DownloadMission
|
||||
from .._base.browser import Browser
|
||||
from .._base.browser import Chromium
|
||||
from .._elements.chromium_element import ChromiumElement
|
||||
from .._pages.chromium_base import ChromiumBase
|
||||
from .._pages.chromium_frame import ChromiumFrame
|
||||
@ -20,7 +20,7 @@ class OriginWaiter(object):
|
||||
|
||||
|
||||
class BrowserWaiter(OriginWaiter):
|
||||
def __init__(self, owner: Browser):
|
||||
def __init__(self, owner: Chromium):
|
||||
self._owner = owner
|
||||
|
||||
def download_begin(self, timeout: float = None, cancel_it: bool = False) -> DownloadMission: ...
|
||||
|
@ -5,6 +5,7 @@
|
||||
@Copyright: (c) 2024 by g1879, Inc. All Rights Reserved.
|
||||
@License : BSD 3-Clause.
|
||||
"""
|
||||
from ._base.browser import Chromium
|
||||
from ._elements.session_element import make_session_ele
|
||||
from ._functions.by import By
|
||||
from ._functions.elements import get_eles
|
||||
@ -12,7 +13,7 @@ from ._functions.keys import Keys
|
||||
from ._functions.settings import Settings
|
||||
from ._functions.tools import wait_until, configs_to_here
|
||||
from ._functions.web import get_blob, tree
|
||||
from ._pages.chromium_page import ChromiumPage
|
||||
|
||||
from ._units.actions import Actions
|
||||
|
||||
__all__ = ['make_session_ele', 'Actions', 'Keys', 'By', 'Settings', 'wait_until', 'configs_to_here', 'get_blob',
|
||||
@ -20,15 +21,15 @@ __all__ = ['make_session_ele', 'Actions', 'Keys', 'By', 'Settings', 'wait_until'
|
||||
|
||||
|
||||
def from_selenium(driver):
|
||||
"""从selenium的WebDriver对象生成ChromiumPage对象"""
|
||||
"""从selenium的WebDriver对象生成Chromium对象"""
|
||||
address, port = driver.caps.get('goog:chromeOptions', {}).get('debuggerAddress', ':').split(':')
|
||||
if not address:
|
||||
raise RuntimeError('获取失败。')
|
||||
return ChromiumPage(f'{address}:{port}')
|
||||
return Chromium(f'{address}:{port}')
|
||||
|
||||
|
||||
def from_playwright(page_or_browser):
|
||||
"""从playwright的Page或Browser对象生成ChromiumPage对象"""
|
||||
"""从playwright的Page或Browser对象生成Chromium对象"""
|
||||
if hasattr(page_or_browser, 'context'):
|
||||
page_or_browser = page_or_browser.context.browser
|
||||
try:
|
||||
@ -49,4 +50,4 @@ def from_playwright(page_or_browser):
|
||||
break
|
||||
else:
|
||||
raise RuntimeError('获取失败。')
|
||||
return ChromiumPage(f'127.0.0.1:{port}')
|
||||
return Chromium(f'127.0.0.1:{port}')
|
||||
|
Loading…
x
Reference in New Issue
Block a user