mirror of
https://gitee.com/g1879/DrissionPage.git
synced 2024-12-10 04:00:23 +08:00
WebPage改名为MixPage
This commit is contained in:
parent
7fdd976854
commit
4cf63e9b08
@ -8,9 +8,10 @@
|
|||||||
from ._base.browser import Chromium
|
from ._base.browser import Chromium
|
||||||
from ._configs.chromium_options import ChromiumOptions
|
from ._configs.chromium_options import ChromiumOptions
|
||||||
from ._configs.session_options import SessionOptions
|
from ._configs.session_options import SessionOptions
|
||||||
# 即将废弃
|
|
||||||
from ._pages.chromium_page import ChromiumPage
|
|
||||||
from ._pages.session_page import SessionPage
|
from ._pages.session_page import SessionPage
|
||||||
from ._pages.web_page import WebPage
|
|
||||||
|
from ._pages.chromium_page import ChromiumPage
|
||||||
|
from ._pages.mix_page import MixPage
|
||||||
|
from ._pages.mix_page import MixPage as WebPage
|
||||||
|
|
||||||
__version__ = '4.1.0.0b1'
|
__version__ = '4.1.0.0b1'
|
||||||
|
@ -11,7 +11,8 @@ from ._configs.session_options import SessionOptions
|
|||||||
from ._pages.session_page import SessionPage
|
from ._pages.session_page import SessionPage
|
||||||
|
|
||||||
from ._pages.chromium_page import ChromiumPage
|
from ._pages.chromium_page import ChromiumPage
|
||||||
from ._pages.web_page import WebPage
|
from ._pages.mix_page import MixPage
|
||||||
|
from ._pages.mix_page import MixPage as WebPage
|
||||||
|
|
||||||
__all__ = ['WebPage', 'ChromiumPage', 'Chromium', 'ChromiumOptions', 'SessionOptions', 'SessionPage', '__version__']
|
__all__ = ['MixPage', 'WebPage', 'ChromiumPage', 'Chromium', 'ChromiumOptions', 'SessionOptions', 'SessionPage', '__version__']
|
||||||
__version__: str = ...
|
__version__: str = ...
|
||||||
|
@ -346,7 +346,6 @@ class BasePage(BaseParser):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
"""初始化函数"""
|
"""初始化函数"""
|
||||||
self._url = None
|
self._url = None
|
||||||
self._timeout = 10
|
|
||||||
self._url_available = None
|
self._url_available = None
|
||||||
self.retry_times = 3
|
self.retry_times = 3
|
||||||
self.retry_interval = 2
|
self.retry_interval = 2
|
||||||
@ -362,11 +361,6 @@ class BasePage(BaseParser):
|
|||||||
ele = self._ele('xpath://title', raise_err=False, method='title')
|
ele = self._ele('xpath://title', raise_err=False, method='title')
|
||||||
return ele.text if ele else None
|
return ele.text if ele else None
|
||||||
|
|
||||||
@property
|
|
||||||
def timeout(self):
|
|
||||||
"""返回查找元素时等待的秒数"""
|
|
||||||
return self._timeout
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def url_available(self):
|
def url_available(self):
|
||||||
"""返回当前访问的url有效性"""
|
"""返回当前访问的url有效性"""
|
||||||
|
@ -15,7 +15,7 @@ from .._elements.session_element import SessionElement
|
|||||||
from .._functions.elements import SessionElementsList
|
from .._functions.elements import SessionElementsList
|
||||||
from .._pages.chromium_page import ChromiumPage
|
from .._pages.chromium_page import ChromiumPage
|
||||||
from .._pages.session_page import SessionPage
|
from .._pages.session_page import SessionPage
|
||||||
from .._pages.web_page import WebPage
|
from .._pages.mix_page import MixPage
|
||||||
|
|
||||||
|
|
||||||
class BaseParser(object):
|
class BaseParser(object):
|
||||||
@ -59,7 +59,6 @@ class BaseElement(BaseParser):
|
|||||||
|
|
||||||
def __init__(self, owner: BasePage = None):
|
def __init__(self, owner: BasePage = None):
|
||||||
self.owner: BasePage = ...
|
self.owner: BasePage = ...
|
||||||
# self.page: Union[ChromiumPage, SessionPage, WebPage] = ...
|
|
||||||
|
|
||||||
# ----------------以下属性或方法由后代实现----------------
|
# ----------------以下属性或方法由后代实现----------------
|
||||||
@property
|
@property
|
||||||
@ -200,19 +199,15 @@ class BasePage(BaseParser):
|
|||||||
self._url_available: bool = ...
|
self._url_available: bool = ...
|
||||||
self.retry_times: int = ...
|
self.retry_times: int = ...
|
||||||
self.retry_interval: float = ...
|
self.retry_interval: float = ...
|
||||||
self._timeout: float = ...
|
|
||||||
self._download_path: str = ...
|
self._download_path: str = ...
|
||||||
self._DownloadKit: DownloadKit = ...
|
self._DownloadKit: DownloadKit = ...
|
||||||
self._none_ele_return_value: bool = ...
|
self._none_ele_return_value: bool = ...
|
||||||
self._none_ele_value: Any = ...
|
self._none_ele_value: Any = ...
|
||||||
self._page: Union[ChromiumPage, SessionPage, WebPage] = ...
|
self._page: Union[ChromiumPage, SessionPage, MixPage] = ...
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def title(self) -> Union[str, None]: ...
|
def title(self) -> Union[str, None]: ...
|
||||||
|
|
||||||
@property
|
|
||||||
def timeout(self) -> float: ...
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def url_available(self) -> bool: ...
|
def url_available(self) -> bool: ...
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ from .._functions.settings import Settings
|
|||||||
from .._functions.tools import PortFinder
|
from .._functions.tools import PortFinder
|
||||||
from .._functions.tools import raise_error
|
from .._functions.tools import raise_error
|
||||||
from .._pages.chromium_base import Timeout
|
from .._pages.chromium_base import Timeout
|
||||||
from .._pages.chromium_tab import ChromiumTab, MixTab
|
from .._pages.tabs import ChromiumTab, MixTab
|
||||||
from .._units.downloader import DownloadManager
|
from .._units.downloader import DownloadManager
|
||||||
from .._units.setter import BrowserSetter
|
from .._units.setter import BrowserSetter
|
||||||
from .._units.waiter import BrowserWaiter
|
from .._units.waiter import BrowserWaiter
|
||||||
|
@ -13,7 +13,7 @@ from .._configs.chromium_options import ChromiumOptions
|
|||||||
from .._configs.session_options import SessionOptions
|
from .._configs.session_options import SessionOptions
|
||||||
from .._functions.cookies import CookiesList
|
from .._functions.cookies import CookiesList
|
||||||
from .._pages.chromium_base import Timeout
|
from .._pages.chromium_base import Timeout
|
||||||
from .._pages.chromium_tab import ChromiumTab, MixTab
|
from .._pages.tabs import ChromiumTab, MixTab
|
||||||
from .._units.downloader import DownloadManager
|
from .._units.downloader import DownloadManager
|
||||||
from .._units.setter import BrowserSetter
|
from .._units.setter import BrowserSetter
|
||||||
from .._units.waiter import BrowserWaiter
|
from .._units.waiter import BrowserWaiter
|
||||||
|
@ -584,7 +584,7 @@ class ChromiumElement(DrissionElement):
|
|||||||
:param locator: 元素的定位信息,可以是loc元组,或查询字符串
|
:param locator: 元素的定位信息,可以是loc元组,或查询字符串
|
||||||
:param timeout: 查找元素超时时间(秒)
|
:param timeout: 查找元素超时时间(秒)
|
||||||
:param index: 第几个结果,从1开始,可传入负数获取倒数第几个,为None返回所有
|
:param index: 第几个结果,从1开始,可传入负数获取倒数第几个,为None返回所有
|
||||||
:param relative: WebPage用的表示是否相对定位的参数
|
:param relative: MixTab用的表示是否相对定位的参数
|
||||||
:param raise_err: 找不到元素是是否抛出异常,为None时根据全局设置
|
:param raise_err: 找不到元素是是否抛出异常,为None时根据全局设置
|
||||||
:return: ChromiumElement对象或文本、属性或其组成的列表
|
:return: ChromiumElement对象或文本、属性或其组成的列表
|
||||||
"""
|
"""
|
||||||
@ -1174,7 +1174,7 @@ class ShadowRoot(BaseElement):
|
|||||||
:param locator: 元素的定位信息,可以是loc元组,或查询字符串
|
:param locator: 元素的定位信息,可以是loc元组,或查询字符串
|
||||||
:param timeout: 查找元素超时时间(秒)
|
:param timeout: 查找元素超时时间(秒)
|
||||||
:param index: 第几个结果,从1开始,可传入负数获取倒数第几个,为None返回所有
|
:param index: 第几个结果,从1开始,可传入负数获取倒数第几个,为None返回所有
|
||||||
:param relative: WebPage用的表示是否相对定位的参数
|
:param relative: MixTab用的表示是否相对定位的参数
|
||||||
:param raise_err: 找不到元素是是否抛出异常,为None时根据全局设置
|
:param raise_err: 找不到元素是是否抛出异常,为None时根据全局设置
|
||||||
:return: ChromiumElement对象或其组成的列表
|
:return: ChromiumElement对象或其组成的列表
|
||||||
"""
|
"""
|
||||||
@ -1250,7 +1250,7 @@ def find_in_chromium_ele(ele, locator, index=1, timeout=None, relative=True):
|
|||||||
:param locator: 元素定位元组
|
:param locator: 元素定位元组
|
||||||
:param index: 第几个结果,从1开始,可传入负数获取倒数第几个,为None返回所有
|
:param index: 第几个结果,从1开始,可传入负数获取倒数第几个,为None返回所有
|
||||||
:param timeout: 查找元素超时时间(秒)
|
:param timeout: 查找元素超时时间(秒)
|
||||||
:param relative: WebPage用于标记是否相对定位使用
|
:param relative: MixTab用于标记是否相对定位使用
|
||||||
:return: 返回ChromiumElement元素或它们组成的列表
|
:return: 返回ChromiumElement元素或它们组成的列表
|
||||||
"""
|
"""
|
||||||
# ---------------处理定位符---------------
|
# ---------------处理定位符---------------
|
||||||
|
@ -14,8 +14,8 @@ from .._functions.elements import SessionElementsList, ChromiumElementsList
|
|||||||
from .._pages.chromium_base import ChromiumBase
|
from .._pages.chromium_base import ChromiumBase
|
||||||
from .._pages.chromium_frame import ChromiumFrame
|
from .._pages.chromium_frame import ChromiumFrame
|
||||||
from .._pages.chromium_page import ChromiumPage
|
from .._pages.chromium_page import ChromiumPage
|
||||||
from .._pages.chromium_tab import ChromiumTab
|
from .._pages.tabs import ChromiumTab
|
||||||
from .._pages.web_page import WebPage
|
from .._pages.mix_page import MixPage
|
||||||
from .._units.clicker import Clicker
|
from .._units.clicker import Clicker
|
||||||
from .._units.rect import ElementRect
|
from .._units.rect import ElementRect
|
||||||
from .._units.scroller import ElementScroller
|
from .._units.scroller import ElementScroller
|
||||||
@ -31,9 +31,8 @@ class ChromiumElement(DrissionElement):
|
|||||||
|
|
||||||
def __init__(self, owner: ChromiumBase, node_id: int = None, obj_id: str = None, backend_id: int = None):
|
def __init__(self, owner: ChromiumBase, node_id: int = None, obj_id: str = None, backend_id: int = None):
|
||||||
self._tag: str = ...
|
self._tag: str = ...
|
||||||
# self.page: Union[ChromiumPage, WebPage] = ...
|
|
||||||
self.owner: ChromiumBase = ...
|
self.owner: ChromiumBase = ...
|
||||||
self.page: Union[ChromiumPage, WebPage] = ...
|
self.page: Union[ChromiumPage, MixPage] = ...
|
||||||
self.tab: Union[ChromiumPage, ChromiumTab] = ...
|
self.tab: Union[ChromiumPage, ChromiumTab] = ...
|
||||||
self._node_id: int = ...
|
self._node_id: int = ...
|
||||||
self._obj_id: str = ...
|
self._obj_id: str = ...
|
||||||
@ -268,7 +267,6 @@ class ChromiumElement(DrissionElement):
|
|||||||
class ShadowRoot(BaseElement):
|
class ShadowRoot(BaseElement):
|
||||||
|
|
||||||
def __init__(self, parent_ele: ChromiumElement, obj_id: str = None, backend_id: int = None):
|
def __init__(self, parent_ele: ChromiumElement, obj_id: str = None, backend_id: int = None):
|
||||||
# self.page: Union[ChromiumPage, WebPage] = ...
|
|
||||||
self.owner: ChromiumBase = ...
|
self.owner: ChromiumBase = ...
|
||||||
self.tab: Union[ChromiumPage, ChromiumTab] = ...
|
self.tab: Union[ChromiumPage, ChromiumTab] = ...
|
||||||
self._obj_id: str = ...
|
self._obj_id: str = ...
|
||||||
@ -379,7 +377,7 @@ def find_by_css(ele: ChromiumElement,
|
|||||||
timeout: float) -> Union[ChromiumElement, List[ChromiumElement],]: ...
|
timeout: float) -> Union[ChromiumElement, List[ChromiumElement],]: ...
|
||||||
|
|
||||||
|
|
||||||
def make_chromium_eles(page: Union[ChromiumBase, ChromiumPage, WebPage, ChromiumTab, ChromiumFrame],
|
def make_chromium_eles(page: Union[ChromiumBase, ChromiumPage, MixPage, ChromiumTab, ChromiumFrame],
|
||||||
_ids: Union[tuple, list, str, int],
|
_ids: Union[tuple, list, str, int],
|
||||||
index: Optional[int] = 1,
|
index: Optional[int] = 1,
|
||||||
is_obj_id: bool = True,
|
is_obj_id: bool = True,
|
||||||
|
@ -260,7 +260,7 @@ class SessionElement(DrissionElement):
|
|||||||
:param locator: 元素的定位信息,可以是loc元组,或查询字符串
|
:param locator: 元素的定位信息,可以是loc元组,或查询字符串
|
||||||
:param timeout: 不起实际作用,用于和父类对应
|
:param timeout: 不起实际作用,用于和父类对应
|
||||||
:param index: 第几个结果,从1开始,可传入负数获取倒数第几个,为None返回所有
|
:param index: 第几个结果,从1开始,可传入负数获取倒数第几个,为None返回所有
|
||||||
:param relative: WebPage用的表示是否相对定位的参数
|
:param relative: MixTab用的表示是否相对定位的参数
|
||||||
:param raise_err: 找不到元素是是否抛出异常,为None时根据全局设置
|
:param raise_err: 找不到元素是是否抛出异常,为None时根据全局设置
|
||||||
:return: SessionElement对象
|
:return: SessionElement对象
|
||||||
"""
|
"""
|
||||||
|
@ -12,7 +12,7 @@ from .._base.base import DrissionElement, BaseParser
|
|||||||
from .._elements.chromium_element import ChromiumElement
|
from .._elements.chromium_element import ChromiumElement
|
||||||
from .._pages.chromium_base import ChromiumBase
|
from .._pages.chromium_base import ChromiumBase
|
||||||
from .._pages.chromium_page import ChromiumPage
|
from .._pages.chromium_page import ChromiumPage
|
||||||
from .._pages.chromium_tab import ChromiumTab
|
from .._pages.tabs import ChromiumTab
|
||||||
|
|
||||||
|
|
||||||
def get_ele_txt(e: DrissionElement) -> str: ...
|
def get_ele_txt(e: DrissionElement) -> str: ...
|
||||||
|
@ -313,6 +313,11 @@ class ChromiumBase(BasePage):
|
|||||||
self._rect = TabRect(self)
|
self._rect = TabRect(self)
|
||||||
return self._rect
|
return self._rect
|
||||||
|
|
||||||
|
@property
|
||||||
|
def timeout(self):
|
||||||
|
"""返回timeout设置"""
|
||||||
|
return self._timeouts.base
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def timeouts(self):
|
def timeouts(self):
|
||||||
"""返回timeouts设置"""
|
"""返回timeouts设置"""
|
||||||
@ -343,7 +348,7 @@ class ChromiumBase(BasePage):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def _browser_url(self):
|
def _browser_url(self):
|
||||||
"""用于被WebPage覆盖"""
|
"""用于被MixTab覆盖"""
|
||||||
return self.url
|
return self.url
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -556,7 +561,7 @@ class ChromiumBase(BasePage):
|
|||||||
:param locator: 定位符或元素对象
|
:param locator: 定位符或元素对象
|
||||||
:param timeout: 查找超时时间(秒)
|
:param timeout: 查找超时时间(秒)
|
||||||
:param index: 第几个结果,从1开始,可传入负数获取倒数第几个,为None返回所有
|
:param index: 第几个结果,从1开始,可传入负数获取倒数第几个,为None返回所有
|
||||||
:param relative: WebPage用的表示是否相对定位的参数
|
:param relative: MixTab用的表示是否相对定位的参数
|
||||||
:param raise_err: 找不到元素是是否抛出异常,为None时根据全局设置
|
:param raise_err: 找不到元素是是否抛出异常,为None时根据全局设置
|
||||||
:return: ChromiumElement对象或元素对象组成的列表
|
:return: ChromiumElement对象或元素对象组成的列表
|
||||||
"""
|
"""
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Union, Tuple, List, Any, Optional, Literal
|
from typing import Union, Tuple, List, Any, Optional, Literal
|
||||||
|
|
||||||
from .chromium_tab import ChromiumTab, MixTab
|
from .tabs import ChromiumTab, MixTab
|
||||||
from .._base.base import BasePage
|
from .._base.base import BasePage
|
||||||
from .._base.browser import Chromium
|
from .._base.browser import Chromium
|
||||||
from .._base.driver import Driver
|
from .._base.driver import Driver
|
||||||
@ -143,6 +143,9 @@ class ChromiumBase(BasePage):
|
|||||||
@property
|
@property
|
||||||
def rect(self) -> TabRect: ...
|
def rect(self) -> TabRect: ...
|
||||||
|
|
||||||
|
@property
|
||||||
|
def timeout(self) -> float: ...
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def timeouts(self) -> Timeout: ...
|
def timeouts(self) -> Timeout: ...
|
||||||
|
|
||||||
|
@ -555,7 +555,7 @@ class ChromiumFrame(ChromiumBase):
|
|||||||
:param locator: 定位符或元素对象
|
:param locator: 定位符或元素对象
|
||||||
:param timeout: 查找超时时间(秒)
|
:param timeout: 查找超时时间(秒)
|
||||||
:param index: 第几个结果,从1开始,可传入负数获取倒数第几个,为None返回所有
|
:param index: 第几个结果,从1开始,可传入负数获取倒数第几个,为None返回所有
|
||||||
:param relative: WebPage用的表示是否相对定位的参数
|
:param relative: MixTab用的表示是否相对定位的参数
|
||||||
:param raise_err: 找不到元素是是否抛出异常,为None时根据全局设置
|
:param raise_err: 找不到元素是是否抛出异常,为None时根据全局设置
|
||||||
:return: ChromiumElement对象
|
:return: ChromiumElement对象
|
||||||
"""
|
"""
|
||||||
|
@ -9,7 +9,7 @@ from pathlib import Path
|
|||||||
from typing import Union, Tuple, List, Any, Optional
|
from typing import Union, Tuple, List, Any, Optional
|
||||||
|
|
||||||
from .chromium_base import ChromiumBase
|
from .chromium_base import ChromiumBase
|
||||||
from .chromium_tab import ChromiumTab, MixTab
|
from .tabs import ChromiumTab, MixTab
|
||||||
from .._elements.chromium_element import ChromiumElement
|
from .._elements.chromium_element import ChromiumElement
|
||||||
from .._functions.elements import ChromiumElementsList
|
from .._functions.elements import ChromiumElementsList
|
||||||
from .._units.listener import FrameListener
|
from .._units.listener import FrameListener
|
||||||
|
@ -11,7 +11,7 @@ from typing import Union, Tuple, List, Optional
|
|||||||
from .._base.browser import Chromium
|
from .._base.browser import Chromium
|
||||||
from .._configs.chromium_options import ChromiumOptions
|
from .._configs.chromium_options import ChromiumOptions
|
||||||
from .._pages.chromium_base import ChromiumBase
|
from .._pages.chromium_base import ChromiumBase
|
||||||
from .._pages.chromium_tab import ChromiumTab
|
from .._pages.tabs import ChromiumTab
|
||||||
from .._units.rect import TabRect
|
from .._units.rect import TabRect
|
||||||
from .._units.setter import ChromiumPageSetter
|
from .._units.setter import ChromiumPageSetter
|
||||||
from .._units.waiter import PageWaiter
|
from .._units.waiter import PageWaiter
|
||||||
|
@ -10,10 +10,10 @@ from .session_page import SessionPage
|
|||||||
from .._base.base import BasePage
|
from .._base.base import BasePage
|
||||||
from .._configs.chromium_options import ChromiumOptions
|
from .._configs.chromium_options import ChromiumOptions
|
||||||
from .._functions.cookies import set_session_cookies, set_tab_cookies
|
from .._functions.cookies import set_session_cookies, set_tab_cookies
|
||||||
from .._units.setter import WebPageSetter
|
from .._units.setter import MixPageSetter
|
||||||
|
|
||||||
|
|
||||||
class WebPage(SessionPage, ChromiumPage, BasePage):
|
class MixPage(SessionPage, ChromiumPage, BasePage):
|
||||||
"""整合浏览器和request的页面类"""
|
"""整合浏览器和request的页面类"""
|
||||||
|
|
||||||
def __new__(cls, mode='d', timeout=None, chromium_options=None, session_or_options=None):
|
def __new__(cls, mode='d', timeout=None, chromium_options=None, session_or_options=None):
|
||||||
@ -46,7 +46,7 @@ class WebPage(SessionPage, ChromiumPage, BasePage):
|
|||||||
chromium_options = ChromiumOptions(read_file=chromium_options)
|
chromium_options = ChromiumOptions(read_file=chromium_options)
|
||||||
chromium_options.set_timeouts(base=self._timeout).set_paths(download_path=self.download_path)
|
chromium_options.set_timeouts(base=self._timeout).set_paths(download_path=self.download_path)
|
||||||
super(SessionPage, self).__init__(addr_or_opts=chromium_options, timeout=timeout)
|
super(SessionPage, self).__init__(addr_or_opts=chromium_options, timeout=timeout)
|
||||||
self._type = 'WebPage'
|
self._type = 'MixPage'
|
||||||
self.change_mode(self._mode, go=False, copy_cookies=False)
|
self.change_mode(self._mode, go=False, copy_cookies=False)
|
||||||
|
|
||||||
def __call__(self, locator, index=1, timeout=None):
|
def __call__(self, locator, index=1, timeout=None):
|
||||||
@ -66,7 +66,7 @@ class WebPage(SessionPage, ChromiumPage, BasePage):
|
|||||||
def set(self):
|
def set(self):
|
||||||
"""返回用于设置的对象"""
|
"""返回用于设置的对象"""
|
||||||
if self._set is None:
|
if self._set is None:
|
||||||
self._set = WebPageSetter(self)
|
self._set = MixPageSetter(self)
|
||||||
return self._set
|
return self._set
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -147,7 +147,7 @@ class WebPage(SessionPage, ChromiumPage, BasePage):
|
|||||||
@property
|
@property
|
||||||
def timeout(self):
|
def timeout(self):
|
||||||
"""返回通用timeout设置"""
|
"""返回通用timeout设置"""
|
||||||
return self.timeouts.base
|
return super()._timeout if self._mode == 's' else self.timeouts.base
|
||||||
|
|
||||||
def get(self, url, show_errmsg=False, retry=None, interval=None, timeout=None, **kwargs):
|
def get(self, url, show_errmsg=False, retry=None, interval=None, timeout=None, **kwargs):
|
||||||
"""跳转到一个url
|
"""跳转到一个url
|
||||||
@ -304,7 +304,7 @@ class WebPage(SessionPage, ChromiumPage, BasePage):
|
|||||||
:param url: 要匹配url的文本,模糊匹配,为None则匹配所有
|
:param url: 要匹配url的文本,模糊匹配,为None则匹配所有
|
||||||
:param tab_type: tab类型,可用列表输入多个,如 'page', 'iframe' 等,为None则匹配所有
|
:param tab_type: tab类型,可用列表输入多个,如 'page', 'iframe' 等,为None则匹配所有
|
||||||
:param as_id: 是否返回标签页id而不是标签页对象
|
:param as_id: 是否返回标签页id而不是标签页对象
|
||||||
:return: WebPageTab对象
|
:return: MixTab对象
|
||||||
"""
|
"""
|
||||||
return self.browser._get_tab(id_or_num=id_or_num, title=title, url=url,
|
return self.browser._get_tab(id_or_num=id_or_num, title=title, url=url,
|
||||||
tab_type=tab_type, mix=True, as_id=as_id)
|
tab_type=tab_type, mix=True, as_id=as_id)
|
||||||
@ -366,7 +366,7 @@ class WebPage(SessionPage, ChromiumPage, BasePage):
|
|||||||
:param locator: 元素的定位信息,可以是元素对象,loc元组,或查询字符串
|
:param locator: 元素的定位信息,可以是元素对象,loc元组,或查询字符串
|
||||||
:param timeout: 查找元素超时时间(秒),d模式专用
|
:param timeout: 查找元素超时时间(秒),d模式专用
|
||||||
:param index: 第几个结果,从1开始,可传入负数获取倒数第几个,为None返回所有
|
:param index: 第几个结果,从1开始,可传入负数获取倒数第几个,为None返回所有
|
||||||
:param relative: WebPage用的表示是否相对定位的参数
|
:param relative: MixTab用的表示是否相对定位的参数
|
||||||
:param raise_err: 找不到元素是是否抛出异常,为None时根据全局设置
|
:param raise_err: 找不到元素是是否抛出异常,为None时根据全局设置
|
||||||
:return: 元素对象或属性、文本节点文本
|
:return: 元素对象或属性、文本节点文本
|
||||||
"""
|
"""
|
||||||
@ -392,4 +392,4 @@ class WebPage(SessionPage, ChromiumPage, BasePage):
|
|||||||
self._has_driver = None
|
self._has_driver = None
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f'<WebPage browser_id={self.browser.id} tab_id={self.tab_id}>'
|
return f'<MixPage browser_id={self.browser.id} tab_id={self.tab_id}>'
|
@ -11,7 +11,7 @@ from requests import Session, Response
|
|||||||
|
|
||||||
from .chromium_frame import ChromiumFrame
|
from .chromium_frame import ChromiumFrame
|
||||||
from .chromium_page import ChromiumPage
|
from .chromium_page import ChromiumPage
|
||||||
from .chromium_tab import MixTab
|
from .tabs import MixTab
|
||||||
from .session_page import SessionPage
|
from .session_page import SessionPage
|
||||||
from .._base.base import BasePage
|
from .._base.base import BasePage
|
||||||
from .._base.driver import Driver
|
from .._base.driver import Driver
|
||||||
@ -20,10 +20,10 @@ from .._configs.session_options import SessionOptions
|
|||||||
from .._elements.chromium_element import ChromiumElement
|
from .._elements.chromium_element import ChromiumElement
|
||||||
from .._elements.session_element import SessionElement
|
from .._elements.session_element import SessionElement
|
||||||
from .._functions.elements import SessionElementsList, ChromiumElementsList
|
from .._functions.elements import SessionElementsList, ChromiumElementsList
|
||||||
from .._units.setter import WebPageSetter
|
from .._units.setter import MixPageSetter
|
||||||
|
|
||||||
|
|
||||||
class WebPage(SessionPage, ChromiumPage, BasePage):
|
class MixPage(SessionPage, ChromiumPage, BasePage):
|
||||||
|
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
mode: str = 'd',
|
mode: str = 'd',
|
||||||
@ -31,7 +31,7 @@ class WebPage(SessionPage, ChromiumPage, BasePage):
|
|||||||
chromium_options: Union[ChromiumOptions, bool] = None,
|
chromium_options: Union[ChromiumOptions, bool] = None,
|
||||||
session_or_options: Union[Session, SessionOptions, bool] = None) -> None:
|
session_or_options: Union[Session, SessionOptions, bool] = None) -> None:
|
||||||
self._mode: str = ...
|
self._mode: str = ...
|
||||||
self._set: WebPageSetter = ...
|
self._set: MixPageSetter = ...
|
||||||
self._has_driver: bool = ...
|
self._has_driver: bool = ...
|
||||||
self._has_session: bool = ...
|
self._has_session: bool = ...
|
||||||
self._session_options: Union[SessionOptions, None] = ...
|
self._session_options: Union[SessionOptions, None] = ...
|
||||||
@ -171,10 +171,10 @@ class WebPage(SessionPage, ChromiumPage, BasePage):
|
|||||||
cert: Any | None = ...) -> Union[bool, Response]: ...
|
cert: Any | None = ...) -> Union[bool, Response]: ...
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def latest_tab(self) -> Union[MixTab, WebPage]: ...
|
def latest_tab(self) -> Union[MixTab, MixPage]: ...
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def set(self) -> WebPageSetter: ...
|
def set(self) -> MixPageSetter: ...
|
||||||
|
|
||||||
def _find_elements(self,
|
def _find_elements(self,
|
||||||
locator: Union[Tuple[str, str], str, ChromiumElement, SessionElement, ChromiumFrame],
|
locator: Union[Tuple[str, str], str, ChromiumElement, SessionElement, ChromiumFrame],
|
@ -38,6 +38,7 @@ class SessionPage(BasePage):
|
|||||||
self._encoding = None
|
self._encoding = None
|
||||||
self._type = 'SessionPage'
|
self._type = 'SessionPage'
|
||||||
self._page = self
|
self._page = self
|
||||||
|
self._timeout = 10
|
||||||
self._s_set_start_options(session_or_options)
|
self._s_set_start_options(session_or_options)
|
||||||
self._s_set_runtime_settings()
|
self._s_set_runtime_settings()
|
||||||
self._create_session()
|
self._create_session()
|
||||||
@ -143,6 +144,11 @@ class SessionPage(BasePage):
|
|||||||
self._set = SessionPageSetter(self)
|
self._set = SessionPageSetter(self)
|
||||||
return self._set
|
return self._set
|
||||||
|
|
||||||
|
@property
|
||||||
|
def timeout(self):
|
||||||
|
"""返回超时设置"""
|
||||||
|
return self._timeout
|
||||||
|
|
||||||
def get(self, url, show_errmsg=False, retry=None, interval=None, timeout=None, **kwargs):
|
def get(self, url, show_errmsg=False, retry=None, interval=None, timeout=None, **kwargs):
|
||||||
"""用get方式跳转到url,可输入文件路径
|
"""用get方式跳转到url,可输入文件路径
|
||||||
:param url: 目标url,可指定本地文件路径
|
:param url: 目标url,可指定本地文件路径
|
||||||
|
@ -130,6 +130,9 @@ class SessionPage(BasePage):
|
|||||||
@property
|
@property
|
||||||
def set(self) -> SessionPageSetter: ...
|
def set(self) -> SessionPageSetter: ...
|
||||||
|
|
||||||
|
@property
|
||||||
|
def timeout(self) -> float: ...
|
||||||
|
|
||||||
def post(self,
|
def post(self,
|
||||||
url: str,
|
url: str,
|
||||||
show_errmsg: bool = False,
|
show_errmsg: bool = False,
|
||||||
|
@ -15,7 +15,7 @@ from .._functions.settings import Settings
|
|||||||
from .._functions.web import save_page
|
from .._functions.web import save_page
|
||||||
from .._pages.chromium_base import ChromiumBase
|
from .._pages.chromium_base import ChromiumBase
|
||||||
from .._pages.session_page import SessionPage
|
from .._pages.session_page import SessionPage
|
||||||
from .._units.setter import TabSetter, WebPageTabSetter
|
from .._units.setter import TabSetter, MixTabSetter
|
||||||
from .._units.waiter import TabWaiter
|
from .._units.waiter import TabWaiter
|
||||||
|
|
||||||
|
|
||||||
@ -52,7 +52,6 @@ class ChromiumTab(ChromiumBase):
|
|||||||
|
|
||||||
def _d_set_runtime_settings(self):
|
def _d_set_runtime_settings(self):
|
||||||
"""重写设置浏览器运行参数方法"""
|
"""重写设置浏览器运行参数方法"""
|
||||||
print('a')
|
|
||||||
self._timeouts = copy(self.browser.timeouts)
|
self._timeouts = copy(self.browser.timeouts)
|
||||||
self.retry_times = self.browser.retry_times
|
self.retry_times = self.browser.retry_times
|
||||||
self.retry_interval = self.browser.retry_interval
|
self.retry_interval = self.browser.retry_interval
|
||||||
@ -127,7 +126,7 @@ class MixTab(SessionPage, ChromiumTab, BasePage):
|
|||||||
def set(self):
|
def set(self):
|
||||||
"""返回用于设置的对象"""
|
"""返回用于设置的对象"""
|
||||||
if self._set is None:
|
if self._set is None:
|
||||||
self._set = WebPageTabSetter(self)
|
self._set = MixTabSetter(self)
|
||||||
return self._set
|
return self._set
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -208,7 +207,7 @@ class MixTab(SessionPage, ChromiumTab, BasePage):
|
|||||||
@property
|
@property
|
||||||
def timeout(self):
|
def timeout(self):
|
||||||
"""返回通用timeout设置"""
|
"""返回通用timeout设置"""
|
||||||
return self.timeouts.base
|
return super()._timeout if self._mode == 's' else self.timeouts.base
|
||||||
|
|
||||||
def get(self, url, show_errmsg=False, retry=None, interval=None, timeout=None, **kwargs):
|
def get(self, url, show_errmsg=False, retry=None, interval=None, timeout=None, **kwargs):
|
||||||
"""跳转到一个url
|
"""跳转到一个url
|
||||||
@ -374,7 +373,7 @@ class MixTab(SessionPage, ChromiumTab, BasePage):
|
|||||||
:param locator: 元素的定位信息,可以是元素对象,loc元组,或查询字符串
|
:param locator: 元素的定位信息,可以是元素对象,loc元组,或查询字符串
|
||||||
:param timeout: 查找元素超时时间(秒),d模式专用
|
:param timeout: 查找元素超时时间(秒),d模式专用
|
||||||
:param index: 第几个结果,从1开始,可传入负数获取倒数第几个,为None返回所有
|
:param index: 第几个结果,从1开始,可传入负数获取倒数第几个,为None返回所有
|
||||||
:param relative: WebPage用的表示是否相对定位的参数
|
:param relative: MixTab用的表示是否相对定位的参数
|
||||||
:param raise_err: 找不到元素是是否抛出异常,为None时根据全局设置
|
:param raise_err: 找不到元素是是否抛出异常,为None时根据全局设置
|
||||||
:return: 元素对象或属性、文本节点文本
|
:return: 元素对象或属性、文本节点文本
|
||||||
"""
|
"""
|
@ -19,7 +19,7 @@ from .._elements.session_element import SessionElement
|
|||||||
from .._functions.cookies import CookiesList
|
from .._functions.cookies import CookiesList
|
||||||
from .._functions.elements import SessionElementsList, ChromiumElementsList
|
from .._functions.elements import SessionElementsList, ChromiumElementsList
|
||||||
from .._units.rect import TabRect
|
from .._units.rect import TabRect
|
||||||
from .._units.setter import TabSetter, WebPageTabSetter
|
from .._units.setter import TabSetter, MixTabSetter
|
||||||
from .._units.waiter import TabWaiter
|
from .._units.waiter import TabWaiter
|
||||||
|
|
||||||
|
|
||||||
@ -180,7 +180,7 @@ class MixTab(SessionPage, ChromiumTab):
|
|||||||
cert: Any | None = ...) -> Union[bool, Response]: ...
|
cert: Any | None = ...) -> Union[bool, Response]: ...
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def set(self) -> WebPageTabSetter: ...
|
def set(self) -> MixTabSetter: ...
|
||||||
|
|
||||||
def _find_elements(self,
|
def _find_elements(self,
|
||||||
locator: Union[Tuple[str, str], str, ChromiumElement, SessionElement, ChromiumFrame],
|
locator: Union[Tuple[str, str], str, ChromiumElement, SessionElement, ChromiumFrame],
|
@ -10,7 +10,7 @@ from typing import Union
|
|||||||
|
|
||||||
from .downloader import DownloadMission
|
from .downloader import DownloadMission
|
||||||
from .._elements.chromium_element import ChromiumElement
|
from .._elements.chromium_element import ChromiumElement
|
||||||
from .._pages.chromium_tab import MixTab, ChromiumTab
|
from .._pages.tabs import MixTab, ChromiumTab
|
||||||
|
|
||||||
|
|
||||||
class Clicker(object):
|
class Clicker(object):
|
||||||
|
@ -79,7 +79,7 @@ class SessionCookiesSetter(object):
|
|||||||
self._owner.session.cookies.clear()
|
self._owner.session.cookies.clear()
|
||||||
|
|
||||||
|
|
||||||
class WebPageCookiesSetter(CookiesSetter, SessionCookiesSetter):
|
class MixPageCookiesSetter(CookiesSetter, SessionCookiesSetter):
|
||||||
|
|
||||||
def __call__(self, cookies):
|
def __call__(self, cookies):
|
||||||
"""设置多个cookie,注意不要传入单个
|
"""设置多个cookie,注意不要传入单个
|
||||||
|
@ -10,9 +10,9 @@ from typing import Union
|
|||||||
|
|
||||||
from .._base.browser import Chromium
|
from .._base.browser import Chromium
|
||||||
from .._pages.chromium_base import ChromiumBase
|
from .._pages.chromium_base import ChromiumBase
|
||||||
from .._pages.chromium_tab import MixTab
|
from .._pages.tabs import MixTab
|
||||||
from .._pages.session_page import SessionPage
|
from .._pages.session_page import SessionPage
|
||||||
from .._pages.web_page import WebPage
|
from .._pages.mix_page import MixPage
|
||||||
|
|
||||||
|
|
||||||
class CookiesSetter(object):
|
class CookiesSetter(object):
|
||||||
@ -45,8 +45,8 @@ class SessionCookiesSetter(object):
|
|||||||
def clear(self) -> None: ...
|
def clear(self) -> None: ...
|
||||||
|
|
||||||
|
|
||||||
class WebPageCookiesSetter(CookiesSetter, SessionCookiesSetter):
|
class MixPageCookiesSetter(CookiesSetter, SessionCookiesSetter):
|
||||||
_owner: Union[WebPage, MixTab] = ...
|
_owner: Union[MixPage, MixTab] = ...
|
||||||
|
|
||||||
def __init__(self, page: SessionPage): ...
|
def __init__(self, page: SessionPage): ...
|
||||||
|
|
||||||
|
@ -12,8 +12,8 @@ from .._elements.chromium_element import ChromiumElement
|
|||||||
from .._pages.chromium_base import ChromiumBase
|
from .._pages.chromium_base import ChromiumBase
|
||||||
from .._pages.chromium_frame import ChromiumFrame
|
from .._pages.chromium_frame import ChromiumFrame
|
||||||
from .._pages.chromium_page import ChromiumPage
|
from .._pages.chromium_page import ChromiumPage
|
||||||
from .._pages.chromium_tab import ChromiumTab, MixTab
|
from .._pages.tabs import ChromiumTab, MixTab
|
||||||
from .._pages.web_page import WebPage
|
from .._pages.mix_page import MixPage
|
||||||
|
|
||||||
|
|
||||||
class ElementRect(object):
|
class ElementRect(object):
|
||||||
@ -66,7 +66,7 @@ class ElementRect(object):
|
|||||||
|
|
||||||
class TabRect(object):
|
class TabRect(object):
|
||||||
def __init__(self, owner: ChromiumBase):
|
def __init__(self, owner: ChromiumBase):
|
||||||
self._owner: Union[ChromiumPage, ChromiumTab, WebPage, MixTab] = ...
|
self._owner: Union[ChromiumPage, ChromiumTab, MixPage, MixTab] = ...
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def window_state(self) -> str: ...
|
def window_state(self) -> str: ...
|
||||||
|
@ -10,14 +10,14 @@ from time import sleep
|
|||||||
|
|
||||||
from requests.structures import CaseInsensitiveDict
|
from requests.structures import CaseInsensitiveDict
|
||||||
|
|
||||||
from .cookies_setter import SessionCookiesSetter, CookiesSetter, WebPageCookiesSetter, BrowserCookiesSetter
|
from .cookies_setter import SessionCookiesSetter, CookiesSetter, MixPageCookiesSetter, BrowserCookiesSetter
|
||||||
from .._functions.settings import Settings
|
from .._functions.settings import Settings
|
||||||
from .._functions.tools import show_or_hide_browser
|
from .._functions.tools import show_or_hide_browser
|
||||||
from .._functions.web import format_headers
|
from .._functions.web import format_headers
|
||||||
from ..errors import ElementLostError, JavaScriptError
|
from ..errors import ElementLostError, JavaScriptError
|
||||||
|
|
||||||
|
|
||||||
class BasePageSetter(object):
|
class BaseSetter(object):
|
||||||
def __init__(self, owner):
|
def __init__(self, owner):
|
||||||
"""
|
"""
|
||||||
:param owner: BasePage对象
|
:param owner: BasePage对象
|
||||||
@ -51,7 +51,144 @@ class BasePageSetter(object):
|
|||||||
self._owner._download_path = str(Path(path).absolute())
|
self._owner._download_path = str(Path(path).absolute())
|
||||||
|
|
||||||
|
|
||||||
class BrowserBaseSetter(BasePageSetter):
|
class SessionPageSetter(BaseSetter):
|
||||||
|
def __init__(self, owner):
|
||||||
|
"""
|
||||||
|
:param owner: SessionPage对象
|
||||||
|
"""
|
||||||
|
super().__init__(owner)
|
||||||
|
self._cookies_setter = None
|
||||||
|
|
||||||
|
@property
|
||||||
|
def cookies(self):
|
||||||
|
"""返回用于设置cookies的对象"""
|
||||||
|
if self._cookies_setter is None:
|
||||||
|
self._cookies_setter = SessionCookiesSetter(self._owner)
|
||||||
|
return self._cookies_setter
|
||||||
|
|
||||||
|
def download_path(self, path):
|
||||||
|
"""设置下载路径
|
||||||
|
:param path: 下载路径
|
||||||
|
:return: None
|
||||||
|
"""
|
||||||
|
super().download_path(path)
|
||||||
|
if self._owner._DownloadKit:
|
||||||
|
self._owner._DownloadKit.set.goal_path(self._owner._download_path)
|
||||||
|
|
||||||
|
def timeout(self, second):
|
||||||
|
"""设置连接超时时间
|
||||||
|
:param second: 秒数
|
||||||
|
:return: None
|
||||||
|
"""
|
||||||
|
self._owner._timeout = second
|
||||||
|
|
||||||
|
def encoding(self, encoding, set_all=True):
|
||||||
|
"""设置编码
|
||||||
|
:param encoding: 编码名称,如果要取消之前的设置,传入None
|
||||||
|
:param set_all: 是否设置对象参数,为False则只设置当前Response
|
||||||
|
:return: None
|
||||||
|
"""
|
||||||
|
if set_all:
|
||||||
|
self._owner._encoding = encoding if encoding else None
|
||||||
|
if self._owner.response:
|
||||||
|
self._owner.response.encoding = encoding
|
||||||
|
|
||||||
|
def headers(self, headers):
|
||||||
|
"""设置通用的headers
|
||||||
|
:param headers: dict形式的headers
|
||||||
|
:return: None
|
||||||
|
"""
|
||||||
|
self._owner._headers = CaseInsensitiveDict(format_headers(headers))
|
||||||
|
|
||||||
|
def header(self, name, value):
|
||||||
|
"""设置headers中一个项
|
||||||
|
:param name: 设置名称
|
||||||
|
:param value: 设置值
|
||||||
|
:return: None
|
||||||
|
"""
|
||||||
|
self._owner._headers[name] = value
|
||||||
|
|
||||||
|
def user_agent(self, ua):
|
||||||
|
"""设置user agent
|
||||||
|
:param ua: user agent
|
||||||
|
:return: None
|
||||||
|
"""
|
||||||
|
self._owner._headers['user-agent'] = ua
|
||||||
|
|
||||||
|
def proxies(self, http=None, https=None):
|
||||||
|
"""设置proxies参数
|
||||||
|
:param http: http代理地址
|
||||||
|
:param https: https代理地址
|
||||||
|
:return: None
|
||||||
|
"""
|
||||||
|
self._owner.session.proxies = {'http': http, 'https': https}
|
||||||
|
|
||||||
|
def auth(self, auth):
|
||||||
|
"""设置认证元组或对象
|
||||||
|
:param auth: 认证元组或对象
|
||||||
|
:return: None
|
||||||
|
"""
|
||||||
|
self._owner.session.auth = auth
|
||||||
|
|
||||||
|
def hooks(self, hooks):
|
||||||
|
"""设置回调方法
|
||||||
|
:param hooks: 回调方法
|
||||||
|
:return: None
|
||||||
|
"""
|
||||||
|
self._owner.session.hooks = hooks
|
||||||
|
|
||||||
|
def params(self, params):
|
||||||
|
"""设置查询参数字典
|
||||||
|
:param params: 查询参数字典
|
||||||
|
:return: None
|
||||||
|
"""
|
||||||
|
self._owner.session.params = params
|
||||||
|
|
||||||
|
def verify(self, on_off):
|
||||||
|
"""设置是否验证SSL证书
|
||||||
|
:param on_off: 是否验证 SSL 证书
|
||||||
|
:return: None
|
||||||
|
"""
|
||||||
|
self._owner.session.verify = on_off
|
||||||
|
|
||||||
|
def cert(self, cert):
|
||||||
|
"""SSL客户端证书文件的路径(.pem格式),或(‘cert’, ‘key’)元组
|
||||||
|
:param cert: 证书路径或元组
|
||||||
|
:return: None
|
||||||
|
"""
|
||||||
|
self._owner.session.cert = cert
|
||||||
|
|
||||||
|
def stream(self, on_off):
|
||||||
|
"""设置是否使用流式响应内容
|
||||||
|
:param on_off: 是否使用流式响应内容
|
||||||
|
:return: None
|
||||||
|
"""
|
||||||
|
self._owner.session.stream = on_off
|
||||||
|
|
||||||
|
def trust_env(self, on_off):
|
||||||
|
"""设置是否信任环境
|
||||||
|
:param on_off: 是否信任环境
|
||||||
|
:return: None
|
||||||
|
"""
|
||||||
|
self._owner.session.trust_env = on_off
|
||||||
|
|
||||||
|
def max_redirects(self, times):
|
||||||
|
"""设置最大重定向次数
|
||||||
|
:param times: 最大重定向次数
|
||||||
|
:return: None
|
||||||
|
"""
|
||||||
|
self._owner.session.max_redirects = times
|
||||||
|
|
||||||
|
def add_adapter(self, url, adapter):
|
||||||
|
"""添加适配器
|
||||||
|
:param url: 适配器对应url
|
||||||
|
:param adapter: 适配器对象
|
||||||
|
:return: None
|
||||||
|
"""
|
||||||
|
self._owner.session.mount(url, adapter)
|
||||||
|
|
||||||
|
|
||||||
|
class BrowserBaseSetter(BaseSetter):
|
||||||
"""Browser和ChromiumBase设置"""
|
"""Browser和ChromiumBase设置"""
|
||||||
|
|
||||||
def __init__(self, owner):
|
def __init__(self, owner):
|
||||||
@ -314,144 +451,7 @@ class ChromiumPageSetter(TabSetter):
|
|||||||
self._owner._alert.auto = accept if on_off else None
|
self._owner._alert.auto = accept if on_off else None
|
||||||
|
|
||||||
|
|
||||||
class SessionPageSetter(BasePageSetter):
|
class MixPageSetter(ChromiumPageSetter):
|
||||||
def __init__(self, owner):
|
|
||||||
"""
|
|
||||||
:param owner: SessionPage对象
|
|
||||||
"""
|
|
||||||
super().__init__(owner)
|
|
||||||
self._cookies_setter = None
|
|
||||||
|
|
||||||
@property
|
|
||||||
def cookies(self):
|
|
||||||
"""返回用于设置cookies的对象"""
|
|
||||||
if self._cookies_setter is None:
|
|
||||||
self._cookies_setter = SessionCookiesSetter(self._owner)
|
|
||||||
return self._cookies_setter
|
|
||||||
|
|
||||||
def download_path(self, path):
|
|
||||||
"""设置下载路径
|
|
||||||
:param path: 下载路径
|
|
||||||
:return: None
|
|
||||||
"""
|
|
||||||
super().download_path(path)
|
|
||||||
if self._owner._DownloadKit:
|
|
||||||
self._owner._DownloadKit.set.goal_path(self._owner._download_path)
|
|
||||||
|
|
||||||
def timeout(self, second):
|
|
||||||
"""设置连接超时时间
|
|
||||||
:param second: 秒数
|
|
||||||
:return: None
|
|
||||||
"""
|
|
||||||
self._owner._timeout = second
|
|
||||||
|
|
||||||
def encoding(self, encoding, set_all=True):
|
|
||||||
"""设置编码
|
|
||||||
:param encoding: 编码名称,如果要取消之前的设置,传入None
|
|
||||||
:param set_all: 是否设置对象参数,为False则只设置当前Response
|
|
||||||
:return: None
|
|
||||||
"""
|
|
||||||
if set_all:
|
|
||||||
self._owner._encoding = encoding if encoding else None
|
|
||||||
if self._owner.response:
|
|
||||||
self._owner.response.encoding = encoding
|
|
||||||
|
|
||||||
def headers(self, headers):
|
|
||||||
"""设置通用的headers
|
|
||||||
:param headers: dict形式的headers
|
|
||||||
:return: None
|
|
||||||
"""
|
|
||||||
self._owner._headers = CaseInsensitiveDict(format_headers(headers))
|
|
||||||
|
|
||||||
def header(self, name, value):
|
|
||||||
"""设置headers中一个项
|
|
||||||
:param name: 设置名称
|
|
||||||
:param value: 设置值
|
|
||||||
:return: None
|
|
||||||
"""
|
|
||||||
self._owner._headers[name] = value
|
|
||||||
|
|
||||||
def user_agent(self, ua):
|
|
||||||
"""设置user agent
|
|
||||||
:param ua: user agent
|
|
||||||
:return: None
|
|
||||||
"""
|
|
||||||
self._owner._headers['user-agent'] = ua
|
|
||||||
|
|
||||||
def proxies(self, http=None, https=None):
|
|
||||||
"""设置proxies参数
|
|
||||||
:param http: http代理地址
|
|
||||||
:param https: https代理地址
|
|
||||||
:return: None
|
|
||||||
"""
|
|
||||||
self._owner.session.proxies = {'http': http, 'https': https}
|
|
||||||
|
|
||||||
def auth(self, auth):
|
|
||||||
"""设置认证元组或对象
|
|
||||||
:param auth: 认证元组或对象
|
|
||||||
:return: None
|
|
||||||
"""
|
|
||||||
self._owner.session.auth = auth
|
|
||||||
|
|
||||||
def hooks(self, hooks):
|
|
||||||
"""设置回调方法
|
|
||||||
:param hooks: 回调方法
|
|
||||||
:return: None
|
|
||||||
"""
|
|
||||||
self._owner.session.hooks = hooks
|
|
||||||
|
|
||||||
def params(self, params):
|
|
||||||
"""设置查询参数字典
|
|
||||||
:param params: 查询参数字典
|
|
||||||
:return: None
|
|
||||||
"""
|
|
||||||
self._owner.session.params = params
|
|
||||||
|
|
||||||
def verify(self, on_off):
|
|
||||||
"""设置是否验证SSL证书
|
|
||||||
:param on_off: 是否验证 SSL 证书
|
|
||||||
:return: None
|
|
||||||
"""
|
|
||||||
self._owner.session.verify = on_off
|
|
||||||
|
|
||||||
def cert(self, cert):
|
|
||||||
"""SSL客户端证书文件的路径(.pem格式),或(‘cert’, ‘key’)元组
|
|
||||||
:param cert: 证书路径或元组
|
|
||||||
:return: None
|
|
||||||
"""
|
|
||||||
self._owner.session.cert = cert
|
|
||||||
|
|
||||||
def stream(self, on_off):
|
|
||||||
"""设置是否使用流式响应内容
|
|
||||||
:param on_off: 是否使用流式响应内容
|
|
||||||
:return: None
|
|
||||||
"""
|
|
||||||
self._owner.session.stream = on_off
|
|
||||||
|
|
||||||
def trust_env(self, on_off):
|
|
||||||
"""设置是否信任环境
|
|
||||||
:param on_off: 是否信任环境
|
|
||||||
:return: None
|
|
||||||
"""
|
|
||||||
self._owner.session.trust_env = on_off
|
|
||||||
|
|
||||||
def max_redirects(self, times):
|
|
||||||
"""设置最大重定向次数
|
|
||||||
:param times: 最大重定向次数
|
|
||||||
:return: None
|
|
||||||
"""
|
|
||||||
self._owner.session.max_redirects = times
|
|
||||||
|
|
||||||
def add_adapter(self, url, adapter):
|
|
||||||
"""添加适配器
|
|
||||||
:param url: 适配器对应url
|
|
||||||
:param adapter: 适配器对象
|
|
||||||
:return: None
|
|
||||||
"""
|
|
||||||
self._owner.session.mount(url, adapter)
|
|
||||||
|
|
||||||
|
|
||||||
class WebPageSetter(ChromiumPageSetter):
|
|
||||||
def __init__(self, owner):
|
def __init__(self, owner):
|
||||||
super().__init__(owner)
|
super().__init__(owner)
|
||||||
self._session_setter = SessionPageSetter(self._owner)
|
self._session_setter = SessionPageSetter(self._owner)
|
||||||
@ -461,7 +461,7 @@ class WebPageSetter(ChromiumPageSetter):
|
|||||||
def cookies(self):
|
def cookies(self):
|
||||||
"""返回用于设置cookies的对象"""
|
"""返回用于设置cookies的对象"""
|
||||||
if self._cookies_setter is None:
|
if self._cookies_setter is None:
|
||||||
self._cookies_setter = WebPageCookiesSetter(self._owner)
|
self._cookies_setter = MixPageCookiesSetter(self._owner)
|
||||||
return self._cookies_setter
|
return self._cookies_setter
|
||||||
|
|
||||||
def headers(self, headers) -> None:
|
def headers(self, headers) -> None:
|
||||||
@ -482,7 +482,7 @@ class WebPageSetter(ChromiumPageSetter):
|
|||||||
self._chromium_setter.user_agent(ua, platform)
|
self._chromium_setter.user_agent(ua, platform)
|
||||||
|
|
||||||
|
|
||||||
class WebPageTabSetter(TabSetter):
|
class MixTabSetter(TabSetter):
|
||||||
def __init__(self, owner):
|
def __init__(self, owner):
|
||||||
super().__init__(owner)
|
super().__init__(owner)
|
||||||
self._session_setter = SessionPageSetter(self._owner)
|
self._session_setter = SessionPageSetter(self._owner)
|
||||||
@ -492,7 +492,7 @@ class WebPageTabSetter(TabSetter):
|
|||||||
def cookies(self):
|
def cookies(self):
|
||||||
"""返回用于设置cookies的对象"""
|
"""返回用于设置cookies的对象"""
|
||||||
if self._cookies_setter is None:
|
if self._cookies_setter is None:
|
||||||
self._cookies_setter = WebPageCookiesSetter(self._owner)
|
self._cookies_setter = MixPageCookiesSetter(self._owner)
|
||||||
return self._cookies_setter
|
return self._cookies_setter
|
||||||
|
|
||||||
def headers(self, headers) -> None:
|
def headers(self, headers) -> None:
|
||||||
@ -512,6 +512,17 @@ class WebPageTabSetter(TabSetter):
|
|||||||
if self._owner._has_driver:
|
if self._owner._has_driver:
|
||||||
self._chromium_setter.user_agent(ua, platform)
|
self._chromium_setter.user_agent(ua, platform)
|
||||||
|
|
||||||
|
def timeouts(self, base=None, page_load=None, script=None):
|
||||||
|
"""设置超时时间,单位为秒
|
||||||
|
:param base: 基本等待时间,除页面加载和脚本超时,其它等待默认使用
|
||||||
|
:param page_load: 页面加载超时时间
|
||||||
|
:param script: 脚本运行超时时间
|
||||||
|
:return: None
|
||||||
|
"""
|
||||||
|
super().timeouts(base=base, page_load=page_load, script=script)
|
||||||
|
if base is not None:
|
||||||
|
self._owner._timeout = base
|
||||||
|
|
||||||
|
|
||||||
class ChromiumElementSetter(object):
|
class ChromiumElementSetter(object):
|
||||||
def __init__(self, ele):
|
def __init__(self, ele):
|
||||||
|
@ -11,7 +11,7 @@ from typing import Union, Tuple, Literal, Any, Optional
|
|||||||
from requests.adapters import HTTPAdapter
|
from requests.adapters import HTTPAdapter
|
||||||
from requests.auth import HTTPBasicAuth
|
from requests.auth import HTTPBasicAuth
|
||||||
|
|
||||||
from .cookies_setter import SessionCookiesSetter, CookiesSetter, WebPageCookiesSetter, BrowserCookiesSetter
|
from .cookies_setter import SessionCookiesSetter, CookiesSetter, MixPageCookiesSetter, BrowserCookiesSetter
|
||||||
from .scroller import PageScroller
|
from .scroller import PageScroller
|
||||||
from .._base.base import BasePage
|
from .._base.base import BasePage
|
||||||
from .._base.browser import Chromium
|
from .._base.browser import Chromium
|
||||||
@ -19,14 +19,14 @@ from .._elements.chromium_element import ChromiumElement
|
|||||||
from .._pages.chromium_base import ChromiumBase
|
from .._pages.chromium_base import ChromiumBase
|
||||||
from .._pages.chromium_frame import ChromiumFrame
|
from .._pages.chromium_frame import ChromiumFrame
|
||||||
from .._pages.chromium_page import ChromiumPage
|
from .._pages.chromium_page import ChromiumPage
|
||||||
from .._pages.chromium_tab import ChromiumTab, MixTab
|
from .._pages.tabs import ChromiumTab, MixTab
|
||||||
from .._pages.session_page import SessionPage
|
from .._pages.session_page import SessionPage
|
||||||
from .._pages.web_page import WebPage
|
from .._pages.mix_page import MixPage
|
||||||
|
|
||||||
FILE_EXISTS = Literal['skip', 'rename', 'overwrite', 's', 'r', 'o']
|
FILE_EXISTS = Literal['skip', 'rename', 'overwrite', 's', 'r', 'o']
|
||||||
|
|
||||||
|
|
||||||
class BasePageSetter(object):
|
class BaseSetter(object):
|
||||||
def __init__(self, owner: Union[Chromium, BasePage]):
|
def __init__(self, owner: Union[Chromium, BasePage]):
|
||||||
self._owner: Union[Chromium, BasePage] = ...
|
self._owner: Union[Chromium, BasePage] = ...
|
||||||
|
|
||||||
@ -39,95 +39,7 @@ class BasePageSetter(object):
|
|||||||
def download_path(self, path: Union[str, Path, None]) -> None: ...
|
def download_path(self, path: Union[str, Path, None]) -> None: ...
|
||||||
|
|
||||||
|
|
||||||
class BrowserBaseSetter(BasePageSetter):
|
class SessionPageSetter(BaseSetter):
|
||||||
_cookies_setter: Optional[CookiesSetter] = ...
|
|
||||||
|
|
||||||
@property
|
|
||||||
def load_mode(self) -> LoadMode: ...
|
|
||||||
|
|
||||||
def timeouts(self, base=None, page_load=None, script=None) -> None: ...
|
|
||||||
|
|
||||||
|
|
||||||
class BrowserSetter(BrowserBaseSetter):
|
|
||||||
_owner: Chromium = ...
|
|
||||||
_cookies_setter: BrowserCookiesSetter = ...
|
|
||||||
|
|
||||||
def tab_to_front(self, tab_or_id: Union[str, ChromiumTab]) -> None: ...
|
|
||||||
|
|
||||||
@property
|
|
||||||
def cookies(self) -> BrowserCookiesSetter: ...
|
|
||||||
|
|
||||||
def auto_handle_alert(self, on_off: bool = True, accept: bool = True): ...
|
|
||||||
|
|
||||||
def download_path(self, path: Union[Path, str, None]): ...
|
|
||||||
|
|
||||||
def download_file_name(self, name: str = None, suffix: str = None): ...
|
|
||||||
|
|
||||||
def when_download_file_exists(self, mode: FILE_EXISTS): ...
|
|
||||||
|
|
||||||
|
|
||||||
class ChromiumBaseSetter(BasePageSetter):
|
|
||||||
_owner: ChromiumBase = ...
|
|
||||||
_cookies_setter: CookiesSetter = ...
|
|
||||||
|
|
||||||
def __init__(self, owner): ...
|
|
||||||
|
|
||||||
@property
|
|
||||||
def load_mode(self) -> LoadMode: ...
|
|
||||||
|
|
||||||
@property
|
|
||||||
def scroll(self) -> PageScrollSetter: ...
|
|
||||||
|
|
||||||
@property
|
|
||||||
def cookies(self) -> CookiesSetter: ...
|
|
||||||
|
|
||||||
def retry_times(self, times: int) -> None: ...
|
|
||||||
|
|
||||||
def retry_interval(self, interval: float) -> None: ...
|
|
||||||
|
|
||||||
def timeouts(self, base: float = None, page_load: float = None, script: float = None) -> None: ...
|
|
||||||
|
|
||||||
def user_agent(self, ua: str, platform: str = None) -> None: ...
|
|
||||||
|
|
||||||
def session_storage(self, item: str, value: Union[str, bool]) -> None: ...
|
|
||||||
|
|
||||||
def local_storage(self, item: str, value: Union[str, bool]) -> None: ...
|
|
||||||
|
|
||||||
def headers(self, headers: Union[dict, str]) -> None: ...
|
|
||||||
|
|
||||||
def auto_handle_alert(self, on_off: bool = True, accept: bool = True) -> None: ...
|
|
||||||
|
|
||||||
def upload_files(self, files: Union[str, Path, list, tuple]) -> None: ...
|
|
||||||
|
|
||||||
def blocked_urls(self, urls: Union[list, tuple, str, None]) -> None: ...
|
|
||||||
|
|
||||||
|
|
||||||
class TabSetter(ChromiumBaseSetter):
|
|
||||||
_owner: ChromiumTab = ...
|
|
||||||
|
|
||||||
def __init__(self, owner: Union[ChromiumTab, MixTab, WebPage, ChromiumPage]): ...
|
|
||||||
|
|
||||||
@property
|
|
||||||
def window(self) -> WindowSetter: ...
|
|
||||||
|
|
||||||
def download_path(self, path: Union[str, Path, None]) -> None: ...
|
|
||||||
|
|
||||||
def download_file_name(self, name: str = None, suffix: str = None) -> None: ...
|
|
||||||
|
|
||||||
def when_download_file_exists(self, mode: FILE_EXISTS) -> None: ...
|
|
||||||
|
|
||||||
def activate(self) -> None: ...
|
|
||||||
|
|
||||||
|
|
||||||
class ChromiumPageSetter(TabSetter):
|
|
||||||
_owner: ChromiumPage = ...
|
|
||||||
|
|
||||||
def tab_to_front(self, tab_or_id: Union[str, ChromiumTab] = None) -> None: ...
|
|
||||||
|
|
||||||
def auto_handle_alert(self, on_off: bool = True, accept: bool = True, all_tabs: bool = False) -> None: ...
|
|
||||||
|
|
||||||
|
|
||||||
class SessionPageSetter(BasePageSetter):
|
|
||||||
_owner: SessionPage = ...
|
_owner: SessionPage = ...
|
||||||
_cookies_setter: Optional[SessionCookiesSetter] = ...
|
_cookies_setter: Optional[SessionCookiesSetter] = ...
|
||||||
|
|
||||||
@ -173,8 +85,87 @@ class SessionPageSetter(BasePageSetter):
|
|||||||
def add_adapter(self, url: str, adapter: HTTPAdapter) -> None: ...
|
def add_adapter(self, url: str, adapter: HTTPAdapter) -> None: ...
|
||||||
|
|
||||||
|
|
||||||
class WebPageSetter(ChromiumPageSetter):
|
class BrowserBaseSetter(BaseSetter):
|
||||||
_owner: WebPage = ...
|
_cookies_setter: Optional[CookiesSetter] = ...
|
||||||
|
|
||||||
|
@property
|
||||||
|
def load_mode(self) -> LoadMode: ...
|
||||||
|
|
||||||
|
def timeouts(self, base=None, page_load=None, script=None) -> None: ...
|
||||||
|
|
||||||
|
|
||||||
|
class BrowserSetter(BrowserBaseSetter):
|
||||||
|
_owner: Chromium = ...
|
||||||
|
_cookies_setter: BrowserCookiesSetter = ...
|
||||||
|
|
||||||
|
def tab_to_front(self, tab_or_id: Union[str, ChromiumTab]) -> None: ...
|
||||||
|
|
||||||
|
@property
|
||||||
|
def cookies(self) -> BrowserCookiesSetter: ...
|
||||||
|
|
||||||
|
def auto_handle_alert(self, on_off: bool = True, accept: bool = True): ...
|
||||||
|
|
||||||
|
def download_path(self, path: Union[Path, str, None]): ...
|
||||||
|
|
||||||
|
def download_file_name(self, name: str = None, suffix: str = None): ...
|
||||||
|
|
||||||
|
def when_download_file_exists(self, mode: FILE_EXISTS): ...
|
||||||
|
|
||||||
|
|
||||||
|
class ChromiumBaseSetter(BrowserBaseSetter):
|
||||||
|
_owner: ChromiumBase = ...
|
||||||
|
_cookies_setter: CookiesSetter = ...
|
||||||
|
|
||||||
|
def __init__(self, owner): ...
|
||||||
|
|
||||||
|
@property
|
||||||
|
def scroll(self) -> PageScrollSetter: ...
|
||||||
|
|
||||||
|
@property
|
||||||
|
def cookies(self) -> CookiesSetter: ...
|
||||||
|
|
||||||
|
def user_agent(self, ua: str, platform: str = None) -> None: ...
|
||||||
|
|
||||||
|
def session_storage(self, item: str, value: Union[str, bool]) -> None: ...
|
||||||
|
|
||||||
|
def local_storage(self, item: str, value: Union[str, bool]) -> None: ...
|
||||||
|
|
||||||
|
def headers(self, headers: Union[dict, str]) -> None: ...
|
||||||
|
|
||||||
|
def auto_handle_alert(self, on_off: bool = True, accept: bool = True) -> None: ...
|
||||||
|
|
||||||
|
def upload_files(self, files: Union[str, Path, list, tuple]) -> None: ...
|
||||||
|
|
||||||
|
def blocked_urls(self, urls: Union[list, tuple, str, None]) -> None: ...
|
||||||
|
|
||||||
|
|
||||||
|
class TabSetter(ChromiumBaseSetter):
|
||||||
|
_owner: ChromiumTab = ...
|
||||||
|
|
||||||
|
def __init__(self, owner: Union[ChromiumTab, MixTab, MixPage, ChromiumPage]): ...
|
||||||
|
|
||||||
|
@property
|
||||||
|
def window(self) -> WindowSetter: ...
|
||||||
|
|
||||||
|
def download_path(self, path: Union[str, Path, None]) -> None: ...
|
||||||
|
|
||||||
|
def download_file_name(self, name: str = None, suffix: str = None) -> None: ...
|
||||||
|
|
||||||
|
def when_download_file_exists(self, mode: FILE_EXISTS) -> None: ...
|
||||||
|
|
||||||
|
def activate(self) -> None: ...
|
||||||
|
|
||||||
|
|
||||||
|
class ChromiumPageSetter(TabSetter):
|
||||||
|
_owner: ChromiumPage = ...
|
||||||
|
|
||||||
|
def tab_to_front(self, tab_or_id: Union[str, ChromiumTab] = None) -> None: ...
|
||||||
|
|
||||||
|
def auto_handle_alert(self, on_off: bool = True, accept: bool = True, all_tabs: bool = False) -> None: ...
|
||||||
|
|
||||||
|
|
||||||
|
class MixPageSetter(ChromiumPageSetter):
|
||||||
|
_owner: MixPage = ...
|
||||||
_session_setter: SessionPageSetter = ...
|
_session_setter: SessionPageSetter = ...
|
||||||
_chromium_setter: ChromiumPageSetter = ...
|
_chromium_setter: ChromiumPageSetter = ...
|
||||||
|
|
||||||
@ -183,10 +174,10 @@ class WebPageSetter(ChromiumPageSetter):
|
|||||||
def headers(self, headers: Union[str, dict]) -> None: ...
|
def headers(self, headers: Union[str, dict]) -> None: ...
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def cookies(self) -> WebPageCookiesSetter: ...
|
def cookies(self) -> MixPageCookiesSetter: ...
|
||||||
|
|
||||||
|
|
||||||
class WebPageTabSetter(TabSetter):
|
class MixTabSetter(TabSetter):
|
||||||
_owner: MixTab = ...
|
_owner: MixTab = ...
|
||||||
_session_setter: SessionPageSetter = ...
|
_session_setter: SessionPageSetter = ...
|
||||||
_chromium_setter: ChromiumBaseSetter = ...
|
_chromium_setter: ChromiumBaseSetter = ...
|
||||||
@ -196,7 +187,9 @@ class WebPageTabSetter(TabSetter):
|
|||||||
def headers(self, headers: Union[str, dict]) -> None: ...
|
def headers(self, headers: Union[str, dict]) -> None: ...
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def cookies(self) -> WebPageCookiesSetter: ...
|
def cookies(self) -> MixPageCookiesSetter: ...
|
||||||
|
|
||||||
|
def timeouts(self, base: float = None, page_load: float = None, script: float = None) -> None: ...
|
||||||
|
|
||||||
|
|
||||||
class ChromiumElementSetter(object):
|
class ChromiumElementSetter(object):
|
||||||
|
@ -9,7 +9,7 @@ from ._elements.chromium_element import ChromiumElement, ShadowRoot
|
|||||||
from ._elements.none_element import NoneElement
|
from ._elements.none_element import NoneElement
|
||||||
from ._elements.session_element import SessionElement
|
from ._elements.session_element import SessionElement
|
||||||
from ._pages.chromium_frame import ChromiumFrame
|
from ._pages.chromium_frame import ChromiumFrame
|
||||||
from ._pages.chromium_tab import ChromiumTab, MixTab
|
from ._pages.tabs import ChromiumTab, MixTab
|
||||||
|
|
||||||
__all__ = ['ChromiumElement', 'ShadowRoot', 'NoneElement', 'SessionElement', 'ChromiumFrame', 'ChromiumTab',
|
__all__ = ['ChromiumElement', 'ShadowRoot', 'NoneElement', 'SessionElement', 'ChromiumFrame', 'ChromiumTab',
|
||||||
'MixTab']
|
'MixTab']
|
||||||
|
Loading…
x
Reference in New Issue
Block a user