diff --git a/DrissionPage/__init__.py b/DrissionPage/__init__.py
index 1f553d7..8a2eaf3 100644
--- a/DrissionPage/__init__.py
+++ b/DrissionPage/__init__.py
@@ -4,10 +4,10 @@
@Contact : g1879@qq.com
"""
# 常用页面类
-from .chromium_page import ChromiumPage
-from .session_page import SessionPage
-from .web_page import WebPage
+from ._pages.chromium_page import ChromiumPage
+from ._pages.session_page import SessionPage
+from ._pages.web_page import WebPage
# 启动配置类
-from .configs.chromium_options import ChromiumOptions
-from .configs.session_options import SessionOptions
+from ._configs.chromium_options import ChromiumOptions
+from ._configs.session_options import SessionOptions
diff --git a/DrissionPage/base.py b/DrissionPage/_base/base.py
similarity index 98%
rename from DrissionPage/base.py
rename to DrissionPage/_base/base.py
index 48880a6..51d7182 100644
--- a/DrissionPage/base.py
+++ b/DrissionPage/_base/base.py
@@ -10,10 +10,10 @@ from urllib.parse import quote
from DownloadKit import DownloadKit
-from .commons.constants import Settings, NoneElement
-from .commons.locator import get_loc
-from .commons.web import format_html
-from .errors import ElementNotFoundError
+from DrissionPage._commons.constants import Settings, NoneElement
+from DrissionPage._commons.locator import get_loc
+from DrissionPage._commons.web import format_html
+from DrissionPage.errors import ElementNotFoundError
class BaseParser(object):
@@ -367,7 +367,7 @@ class BasePage(BaseParser):
self.retry_times = 3
self.retry_interval = 2
self._DownloadKit = None
- self._download_path = str(Path('.').absolute())
+ self._download_path = str(Path('../..').absolute())
@property
def title(self):
diff --git a/DrissionPage/base.pyi b/DrissionPage/_base/base.pyi
similarity index 99%
rename from DrissionPage/base.pyi
rename to DrissionPage/_base/base.pyi
index 6c49719..3ec97a4 100644
--- a/DrissionPage/base.pyi
+++ b/DrissionPage/_base/base.pyi
@@ -8,7 +8,7 @@ from typing import Union, Tuple, List
from DownloadKit import DownloadKit
-from .commons.constants import NoneElement
+from DrissionPage._commons.constants import NoneElement
class BaseParser(object):
diff --git a/DrissionPage/browser.py b/DrissionPage/_base/browser.py
similarity index 97%
rename from DrissionPage/browser.py
rename to DrissionPage/_base/browser.py
index 387ba2d..9019b7f 100644
--- a/DrissionPage/browser.py
+++ b/DrissionPage/_base/browser.py
@@ -1,7 +1,11 @@
# -*- coding:utf-8 -*-
+"""
+@Author : g1879
+@Contact : g1879@qq.com
+"""
from time import sleep
-from .browser_download_manager import BrowserDownloadManager
+from DrissionPage._units.browser_download_manager import BrowserDownloadManager
from .chromium_driver import BrowserDriver
diff --git a/DrissionPage/browser.pyi b/DrissionPage/_base/browser.pyi
similarity index 86%
rename from DrissionPage/browser.pyi
rename to DrissionPage/_base/browser.pyi
index e4672ef..cdee003 100644
--- a/DrissionPage/browser.pyi
+++ b/DrissionPage/_base/browser.pyi
@@ -1,8 +1,12 @@
# -*- coding:utf-8 -*-
+"""
+@Author : g1879
+@Contact : g1879@qq.com
+"""
from typing import List, Optional, Union
-from .browser_download_manager import BrowserDownloadManager
-from .chromium_page import ChromiumPage
+from DrissionPage._units.browser_download_manager import BrowserDownloadManager
+from DrissionPage._pages.chromium_page import ChromiumPage
from .chromium_driver import BrowserDriver
diff --git a/DrissionPage/chromium_driver.py b/DrissionPage/_base/chromium_driver.py
similarity index 100%
rename from DrissionPage/chromium_driver.py
rename to DrissionPage/_base/chromium_driver.py
diff --git a/DrissionPage/chromium_driver.pyi b/DrissionPage/_base/chromium_driver.pyi
similarity index 100%
rename from DrissionPage/chromium_driver.pyi
rename to DrissionPage/_base/chromium_driver.pyi
diff --git a/DrissionPage/commons/browser.py b/DrissionPage/_commons/browser.py
similarity index 100%
rename from DrissionPage/commons/browser.py
rename to DrissionPage/_commons/browser.py
diff --git a/DrissionPage/commons/browser.pyi b/DrissionPage/_commons/browser.pyi
similarity index 78%
rename from DrissionPage/commons/browser.pyi
rename to DrissionPage/_commons/browser.pyi
index ede46db..0294aff 100644
--- a/DrissionPage/commons/browser.pyi
+++ b/DrissionPage/_commons/browser.pyi
@@ -3,7 +3,7 @@
@Author : g1879
@Contact : g1879@qq.com
"""
-from DrissionPage.configs.chromium_options import ChromiumOptions
+from DrissionPage._configs.chromium_options import ChromiumOptions
def connect_browser(option: ChromiumOptions) -> tuple: ...
diff --git a/DrissionPage/commons/by.py b/DrissionPage/_commons/by.py
similarity index 100%
rename from DrissionPage/commons/by.py
rename to DrissionPage/_commons/by.py
diff --git a/DrissionPage/commons/cli.py b/DrissionPage/_commons/cli.py
similarity index 86%
rename from DrissionPage/commons/cli.py
rename to DrissionPage/_commons/cli.py
index cc82107..71f2c28 100644
--- a/DrissionPage/commons/cli.py
+++ b/DrissionPage/_commons/cli.py
@@ -1,6 +1,11 @@
+# -*- coding:utf-8 -*-
+"""
+@Author : g1879
+@Contact : g1879@qq.com
+"""
from click import command, option
-from DrissionPage import ChromiumPage
+from DrissionPage._pages.chromium_page import ChromiumPage
from DrissionPage.easy_set import set_paths, configs_to_here as ch
diff --git a/DrissionPage/commons/constants.py b/DrissionPage/_commons/constants.py
similarity index 100%
rename from DrissionPage/commons/constants.py
rename to DrissionPage/_commons/constants.py
diff --git a/DrissionPage/commons/keys.py b/DrissionPage/_commons/keys.py
similarity index 100%
rename from DrissionPage/commons/keys.py
rename to DrissionPage/_commons/keys.py
diff --git a/DrissionPage/commons/locator.py b/DrissionPage/_commons/locator.py
similarity index 100%
rename from DrissionPage/commons/locator.py
rename to DrissionPage/_commons/locator.py
diff --git a/DrissionPage/commons/locator.pyi b/DrissionPage/_commons/locator.pyi
similarity index 100%
rename from DrissionPage/commons/locator.pyi
rename to DrissionPage/_commons/locator.pyi
diff --git a/DrissionPage/commons/tools.py b/DrissionPage/_commons/tools.py
similarity index 100%
rename from DrissionPage/commons/tools.py
rename to DrissionPage/_commons/tools.py
diff --git a/DrissionPage/commons/tools.pyi b/DrissionPage/_commons/tools.pyi
similarity index 93%
rename from DrissionPage/commons/tools.pyi
rename to DrissionPage/_commons/tools.pyi
index ba8d6ee..83dcff1 100644
--- a/DrissionPage/commons/tools.pyi
+++ b/DrissionPage/_commons/tools.pyi
@@ -8,7 +8,7 @@ from pathlib import Path
from typing import Union
from types import FunctionType
-from chromium_page import ChromiumPage
+from DrissionPage._pages.chromium_page import ChromiumPage
def get_usable_path(path: Union[str, Path], is_file: bool = True, parents: bool = True) -> Path: ...
diff --git a/DrissionPage/commons/web.py b/DrissionPage/_commons/web.py
similarity index 100%
rename from DrissionPage/commons/web.py
rename to DrissionPage/_commons/web.py
diff --git a/DrissionPage/commons/web.pyi b/DrissionPage/_commons/web.pyi
similarity index 90%
rename from DrissionPage/commons/web.pyi
rename to DrissionPage/_commons/web.pyi
index f4b4931..4a365e9 100644
--- a/DrissionPage/commons/web.pyi
+++ b/DrissionPage/_commons/web.pyi
@@ -10,8 +10,8 @@ from requests import Session
from requests.cookies import RequestsCookieJar
from DrissionPage.base import DrissionElement, BasePage
-from DrissionPage.chromium_element import ChromiumElement
-from DrissionPage.chromium_base import ChromiumBase
+from DrissionPage._chromium_element import ChromiumElement
+from DrissionPage._chromium_base import ChromiumBase
def get_ele_txt(e: DrissionElement) -> str: ...
diff --git a/DrissionPage/configs/chromium_options.py b/DrissionPage/_configs/chromium_options.py
similarity index 99%
rename from DrissionPage/configs/chromium_options.py
rename to DrissionPage/_configs/chromium_options.py
index 6f32d90..c44529a 100644
--- a/DrissionPage/configs/chromium_options.py
+++ b/DrissionPage/_configs/chromium_options.py
@@ -6,7 +6,7 @@
from pathlib import Path
from tempfile import gettempdir, TemporaryDirectory
-from DrissionPage.commons.tools import port_is_using, clean_folder
+from DrissionPage._commons.tools import port_is_using, clean_folder
from .options_manage import OptionsManager
diff --git a/DrissionPage/configs/chromium_options.pyi b/DrissionPage/_configs/chromium_options.pyi
similarity index 100%
rename from DrissionPage/configs/chromium_options.pyi
rename to DrissionPage/_configs/chromium_options.pyi
diff --git a/DrissionPage/configs/configs.ini b/DrissionPage/_configs/configs.ini
similarity index 100%
rename from DrissionPage/configs/configs.ini
rename to DrissionPage/_configs/configs.ini
diff --git a/DrissionPage/configs/options_manage.py b/DrissionPage/_configs/options_manage.py
similarity index 100%
rename from DrissionPage/configs/options_manage.py
rename to DrissionPage/_configs/options_manage.py
diff --git a/DrissionPage/configs/options_manage.pyi b/DrissionPage/_configs/options_manage.pyi
similarity index 100%
rename from DrissionPage/configs/options_manage.pyi
rename to DrissionPage/_configs/options_manage.pyi
diff --git a/DrissionPage/configs/session_options.py b/DrissionPage/_configs/session_options.py
similarity index 99%
rename from DrissionPage/configs/session_options.py
rename to DrissionPage/_configs/session_options.py
index 03fc800..1aa7c1d 100644
--- a/DrissionPage/configs/session_options.py
+++ b/DrissionPage/_configs/session_options.py
@@ -8,7 +8,7 @@ from pathlib import Path
from requests import Session
from requests.structures import CaseInsensitiveDict
-from DrissionPage.commons.web import cookies_to_tuple, set_session_cookies
+from DrissionPage._commons.web import cookies_to_tuple, set_session_cookies
from .options_manage import OptionsManager
diff --git a/DrissionPage/configs/session_options.pyi b/DrissionPage/_configs/session_options.pyi
similarity index 100%
rename from DrissionPage/configs/session_options.pyi
rename to DrissionPage/_configs/session_options.pyi
diff --git a/DrissionPage/chromium_element.py b/DrissionPage/_elements/chromium_element.py
similarity index 99%
rename from DrissionPage/chromium_element.py
rename to DrissionPage/_elements/chromium_element.py
index cf12697..f5fc1fd 100644
--- a/DrissionPage/chromium_element.py
+++ b/DrissionPage/_elements/chromium_element.py
@@ -7,17 +7,17 @@ from os.path import basename, sep
from pathlib import Path
from time import perf_counter, sleep
-from .base import DrissionElement, BaseElement
-from .commons.constants import FRAME_ELEMENT, NoneElement, Settings
-from .commons.keys import keys_to_typing, keyDescriptionForString, keyDefinitions
-from .commons.locator import get_loc
-from .commons.tools import get_usable_path
-from .commons.web import make_absolute_link, get_ele_txt, format_html, is_js_func, location_in_viewport, offset_scroll
-from .errors import ContextLossError, ElementLossError, JavaScriptError, NoRectError, ElementNotFoundError, \
+from DrissionPage._base.base import DrissionElement, BaseElement
+from DrissionPage._commons.constants import FRAME_ELEMENT, NoneElement, Settings
+from DrissionPage._commons.keys import keys_to_typing, keyDescriptionForString, keyDefinitions
+from DrissionPage._commons.locator import get_loc
+from DrissionPage._commons.tools import get_usable_path
+from DrissionPage._commons.web import make_absolute_link, get_ele_txt, format_html, is_js_func, location_in_viewport, offset_scroll
+from DrissionPage.errors import ContextLossError, ElementLossError, JavaScriptError, NoRectError, ElementNotFoundError, \
CDPError, NoResourceError, CanNotClickError
from .session_element import make_session_ele
-from .setter import ChromiumElementSetter
-from .waiter import ChromiumElementWaiter
+from DrissionPage._units.setter import ChromiumElementSetter
+from DrissionPage._units.waiter import ChromiumElementWaiter
class ChromiumElement(DrissionElement):
@@ -1203,7 +1203,7 @@ def make_chromium_ele(page, node_id=None, obj_id=None):
ele = ChromiumElement(page, obj_id=obj_id, node_id=node_id, backend_id=backend_id)
if ele.tag in FRAME_ELEMENT:
- from .chromium_frame import ChromiumFrame
+ from ._chromium_frame import ChromiumFrame
ele = ChromiumFrame(page, ele)
return ele
diff --git a/DrissionPage/chromium_element.pyi b/DrissionPage/_elements/chromium_element.pyi
similarity index 96%
rename from DrissionPage/chromium_element.pyi
rename to DrissionPage/_elements/chromium_element.pyi
index 03355d2..a7b0dcb 100644
--- a/DrissionPage/chromium_element.pyi
+++ b/DrissionPage/_elements/chromium_element.pyi
@@ -6,15 +6,15 @@
from pathlib import Path
from typing import Union, Tuple, List, Any
-from .base import DrissionElement, BaseElement
-from .chromium_base import ChromiumBase
-from .chromium_frame import ChromiumFrame
-from .chromium_page import ChromiumPage
-from .commons.constants import NoneElement
-from .session_element import SessionElement
-from .setter import ChromiumElementSetter
-from .waiter import ChromiumElementWaiter
-from .web_page import WebPage
+from DrissionPage._base.base import DrissionElement, BaseElement
+from DrissionPage._commons.constants import NoneElement
+from DrissionPage._elements.session_element import SessionElement
+from DrissionPage._pages.chromium_base import ChromiumBase
+from DrissionPage._pages.chromium_frame import ChromiumFrame
+from DrissionPage._pages.chromium_page import ChromiumPage
+from DrissionPage._pages.web_page import WebPage
+from DrissionPage._units.setter import ChromiumElementSetter
+from DrissionPage._units.waiter import ChromiumElementWaiter
class ChromiumElement(DrissionElement):
diff --git a/DrissionPage/session_element.py b/DrissionPage/_elements/session_element.py
similarity index 98%
rename from DrissionPage/session_element.py
rename to DrissionPage/_elements/session_element.py
index 7e8bb88..fa241cb 100644
--- a/DrissionPage/session_element.py
+++ b/DrissionPage/_elements/session_element.py
@@ -9,10 +9,10 @@ from re import match, DOTALL
from lxml.etree import tostring
from lxml.html import HtmlElement, fromstring
-from .base import DrissionElement, BasePage, BaseElement
-from .commons.constants import NoneElement
-from .commons.locator import get_loc
-from .commons.web import get_ele_txt, make_absolute_link
+from DrissionPage._base.base import DrissionElement, BasePage, BaseElement
+from DrissionPage._commons.constants import NoneElement
+from DrissionPage._commons.locator import get_loc
+from DrissionPage._commons.web import get_ele_txt, make_absolute_link
class SessionElement(DrissionElement):
diff --git a/DrissionPage/session_element.pyi b/DrissionPage/_elements/session_element.pyi
similarity index 92%
rename from DrissionPage/session_element.pyi
rename to DrissionPage/_elements/session_element.pyi
index c55dcfe..9257354 100644
--- a/DrissionPage/session_element.pyi
+++ b/DrissionPage/_elements/session_element.pyi
@@ -7,12 +7,12 @@ from typing import Union, List, Tuple
from lxml.html import HtmlElement
-from .base import DrissionElement, BaseElement
-from .chromium_base import ChromiumBase
-from .chromium_element import ChromiumElement
-from .chromium_frame import ChromiumFrame
-from .commons.constants import NoneElement
-from .session_page import SessionPage
+from DrissionPage._base.base import DrissionElement, BaseElement
+from DrissionPage._commons.constants import NoneElement
+from DrissionPage._elements.chromium_element import ChromiumElement
+from DrissionPage._pages.chromium_base import ChromiumBase
+from DrissionPage._pages.chromium_frame import ChromiumFrame
+from DrissionPage._pages.session_page import SessionPage
class SessionElement(DrissionElement):
diff --git a/DrissionPage/chromium_base.py b/DrissionPage/_pages/chromium_base.py
similarity index 97%
rename from DrissionPage/chromium_base.py
rename to DrissionPage/_pages/chromium_base.py
index d820918..c79b8be 100644
--- a/DrissionPage/chromium_base.py
+++ b/DrissionPage/_pages/chromium_base.py
@@ -13,20 +13,20 @@ from time import perf_counter, sleep, time
from requests import get
-from .action_chains import ActionChains
-from .base import BasePage
-from .chromium_driver import ChromiumDriver
-from .chromium_element import ChromiumScroll, ChromiumElement, run_js, make_chromium_ele
-from .commons.constants import HANDLE_ALERT_METHOD, ERROR, NoneElement
-from .commons.locator import get_loc
-from .commons.tools import get_usable_path, clean_folder
-from .commons.web import location_in_viewport
-from .errors import ContextLossError, ElementLossError, AlertExistsError, CDPError, TabClosedError, \
+from DrissionPage._base.base import BasePage
+from DrissionPage._base.chromium_driver import ChromiumDriver
+from DrissionPage._commons.constants import HANDLE_ALERT_METHOD, ERROR, NoneElement
+from DrissionPage._commons.locator import get_loc
+from DrissionPage._commons.tools import get_usable_path, clean_folder
+from DrissionPage._commons.web import location_in_viewport
+from DrissionPage._elements.chromium_element import ChromiumScroll, ChromiumElement, run_js, make_chromium_ele
+from DrissionPage._elements.session_element import make_session_ele
+from DrissionPage._units.network_listener import NetworkListener
+from DrissionPage._units.setter import ChromiumBaseSetter
+from DrissionPage._units.waiter import ChromiumBaseWaiter
+from DrissionPage.errors import ContextLossError, ElementLossError, AlertExistsError, CDPError, TabClosedError, \
NoRectError, BrowserConnectError, GetDocumentError
-from .network_listener import NetworkListener
-from .session_element import make_session_ele
-from .setter import ChromiumBaseSetter
-from .waiter import ChromiumBaseWaiter
+from _units.action_chains import ActionChains
class ChromiumBase(BasePage):
@@ -48,7 +48,7 @@ class ChromiumBase(BasePage):
self._actions = None
self._listener = None
- self._download_path = str(Path('.').absolute())
+ self._download_path = str(Path('../..').absolute())
if isinstance(address, int) or (isinstance(address, str) and address.isdigit()):
address = f'127.0.0.1:{address}'
diff --git a/DrissionPage/chromium_base.pyi b/DrissionPage/_pages/chromium_base.pyi
similarity index 92%
rename from DrissionPage/chromium_base.pyi
rename to DrissionPage/_pages/chromium_base.pyi
index 3a90a70..97020ad 100644
--- a/DrissionPage/chromium_base.pyi
+++ b/DrissionPage/_pages/chromium_base.pyi
@@ -8,18 +8,18 @@ from typing import Union, Tuple, List, Any
from DataRecorder import Recorder
-from .browser import Browser
-from .action_chains import ActionChains
-from .base import BasePage
-from .chromium_driver import ChromiumDriver
-from .chromium_element import ChromiumElement, ChromiumScroll
-from .chromium_frame import ChromiumFrame
-from .chromium_page import ChromiumPage
-from .commons.constants import NoneElement
-from .network_listener import NetworkListener
-from .session_element import SessionElement
-from .setter import ChromiumBaseSetter
-from .waiter import ChromiumBaseWaiter
+from DrissionPage._base.base import BasePage
+from DrissionPage._base.browser import Browser
+from DrissionPage._base.chromium_driver import ChromiumDriver
+from DrissionPage._commons.constants import NoneElement
+from DrissionPage._elements.chromium_element import ChromiumElement, ChromiumScroll
+from DrissionPage._elements.session_element import SessionElement
+from DrissionPage._pages.chromium_frame import ChromiumFrame
+from DrissionPage._pages.chromium_page import ChromiumPage
+from DrissionPage._units.action_chains import ActionChains
+from DrissionPage._units.network_listener import NetworkListener
+from DrissionPage._units.setter import ChromiumBaseSetter
+from DrissionPage._units.waiter import ChromiumBaseWaiter
class ChromiumBase(BasePage):
diff --git a/DrissionPage/chromium_frame.py b/DrissionPage/_pages/chromium_frame.py
similarity index 98%
rename from DrissionPage/chromium_frame.py
rename to DrissionPage/_pages/chromium_frame.py
index 71d3b0d..ca037f0 100644
--- a/DrissionPage/chromium_frame.py
+++ b/DrissionPage/_pages/chromium_frame.py
@@ -10,11 +10,11 @@ from time import sleep, perf_counter
from requests import get
-from .chromium_base import ChromiumBase, ChromiumPageScroll
-from .chromium_element import ChromiumElement
-from .errors import ContextLossError
-from .setter import ChromiumFrameSetter
-from .waiter import FrameWaiter
+from DrissionPage._elements.chromium_element import ChromiumElement
+from DrissionPage._pages.chromium_base import ChromiumBase, ChromiumPageScroll
+from DrissionPage._units.setter import ChromiumFrameSetter
+from DrissionPage._units.waiter import FrameWaiter
+from DrissionPage.errors import ContextLossError
class ChromiumFrame(ChromiumBase):
diff --git a/DrissionPage/chromium_frame.pyi b/DrissionPage/_pages/chromium_frame.pyi
similarity index 93%
rename from DrissionPage/chromium_frame.pyi
rename to DrissionPage/_pages/chromium_frame.pyi
index 086565a..1be67ad 100644
--- a/DrissionPage/chromium_frame.pyi
+++ b/DrissionPage/_pages/chromium_frame.pyi
@@ -6,12 +6,13 @@
from pathlib import Path
from typing import Union, Tuple, List, Any
-from DrissionPage import ChromiumPage, WebPage
-from .chromium_tab import ChromiumTab
-from .chromium_base import ChromiumBase, ChromiumPageScroll
-from .chromium_element import ChromiumElement, Locations, ChromiumElementStates
-from .setter import ChromiumFrameSetter
-from .waiter import FrameWaiter
+from DrissionPage._elements.chromium_element import ChromiumElement, Locations, ChromiumElementStates
+from DrissionPage._pages.chromium_base import ChromiumBase, ChromiumPageScroll
+from DrissionPage._pages.chromium_page import ChromiumPage
+from DrissionPage._pages.chromium_tab import ChromiumTab
+from DrissionPage._pages.web_page import WebPage
+from DrissionPage._units.setter import ChromiumFrameSetter
+from DrissionPage._units.waiter import FrameWaiter
class ChromiumFrame(ChromiumBase):
diff --git a/DrissionPage/chromium_page.py b/DrissionPage/_pages/chromium_page.py
similarity index 96%
rename from DrissionPage/chromium_page.py
rename to DrissionPage/_pages/chromium_page.py
index bbee74b..33f343b 100644
--- a/DrissionPage/chromium_page.py
+++ b/DrissionPage/_pages/chromium_page.py
@@ -8,14 +8,14 @@ from time import perf_counter, sleep
from requests import get
-from .browser import Browser
-from .chromium_base import ChromiumBase, Timeout
-from .chromium_driver import ChromiumDriver
-from .chromium_tab import ChromiumTab
-from .commons.browser import connect_browser
-from .configs.chromium_options import ChromiumOptions
-from .setter import ChromiumPageSetter
-from .waiter import ChromiumPageWaiter
+from DrissionPage._base.browser import Browser
+from DrissionPage._base.chromium_driver import ChromiumDriver
+from DrissionPage._commons.browser import connect_browser
+from DrissionPage._configs.chromium_options import ChromiumOptions
+from DrissionPage._pages.chromium_base import ChromiumBase, Timeout
+from DrissionPage._pages.chromium_tab import ChromiumTab
+from DrissionPage._units.setter import ChromiumPageSetter
+from DrissionPage._units.waiter import ChromiumPageWaiter
class ChromiumPage(ChromiumBase):
diff --git a/DrissionPage/chromium_page.pyi b/DrissionPage/_pages/chromium_page.pyi
similarity index 89%
rename from DrissionPage/chromium_page.pyi
rename to DrissionPage/_pages/chromium_page.pyi
index a152caa..884a452 100644
--- a/DrissionPage/chromium_page.pyi
+++ b/DrissionPage/_pages/chromium_page.pyi
@@ -5,13 +5,13 @@
"""
from typing import Union, Tuple, List, Optional
-from .browser import Browser
-from .chromium_base import ChromiumBase
-from .chromium_driver import ChromiumDriver
-from .chromium_tab import ChromiumTab
-from .configs.chromium_options import ChromiumOptions
-from .setter import ChromiumPageSetter
-from .waiter import ChromiumPageWaiter
+from DrissionPage._base.browser import Browser
+from DrissionPage._pages.chromium_base import ChromiumBase
+from DrissionPage._base.chromium_driver import ChromiumDriver
+from DrissionPage._pages.chromium_tab import ChromiumTab
+from DrissionPage._configs.chromium_options import ChromiumOptions
+from DrissionPage._units.setter import ChromiumPageSetter
+from DrissionPage._units.waiter import ChromiumPageWaiter
class ChromiumPage(ChromiumBase):
diff --git a/DrissionPage/chromium_tab.py b/DrissionPage/_pages/chromium_tab.py
similarity index 97%
rename from DrissionPage/chromium_tab.py
rename to DrissionPage/_pages/chromium_tab.py
index 556fff4..6e44f6d 100644
--- a/DrissionPage/chromium_tab.py
+++ b/DrissionPage/_pages/chromium_tab.py
@@ -5,13 +5,12 @@
"""
from copy import copy
-from .base import BasePage
-from .chromium_base import ChromiumBase
-from .commons.web import set_session_cookies, set_browser_cookies
-from .session_page import SessionPage
-from .setter import TabSetter
-from .setter import WebPageTabSetter
-from .waiter import ChromiumTabWaiter
+from DrissionPage._base.base import BasePage
+from DrissionPage._commons.web import set_session_cookies, set_browser_cookies
+from DrissionPage._pages.chromium_base import ChromiumBase
+from DrissionPage._pages.session_page import SessionPage
+from DrissionPage._units.setter import TabSetter, WebPageTabSetter
+from DrissionPage._units.waiter import ChromiumTabWaiter
class ChromiumTab(ChromiumBase):
diff --git a/DrissionPage/chromium_tab.pyi b/DrissionPage/_pages/chromium_tab.pyi
similarity index 88%
rename from DrissionPage/chromium_tab.pyi
rename to DrissionPage/_pages/chromium_tab.pyi
index 8a6db8c..6f19d4b 100644
--- a/DrissionPage/chromium_tab.pyi
+++ b/DrissionPage/_pages/chromium_tab.pyi
@@ -7,17 +7,16 @@ from typing import Union, Tuple, Any, List
from requests import Session, Response
-from .browser import Browser
-from .chromium_base import ChromiumBase
-from .chromium_element import ChromiumElement
-from .chromium_frame import ChromiumFrame
-from .chromium_page import ChromiumPage, ChromiumTabRect
-from .session_element import SessionElement
-from .session_page import SessionPage
-from .setter import TabSetter
-from .setter import WebPageTabSetter
-from .waiter import ChromiumTabWaiter
-from .web_page import WebPage
+from DrissionPage._base.browser import Browser
+from DrissionPage._elements.chromium_element import ChromiumElement
+from DrissionPage._elements.session_element import SessionElement
+from DrissionPage._pages.chromium_base import ChromiumBase
+from DrissionPage._pages.chromium_frame import ChromiumFrame
+from DrissionPage._pages.chromium_page import ChromiumPage, ChromiumTabRect
+from DrissionPage._pages.session_page import SessionPage
+from DrissionPage._pages.web_page import WebPage
+from DrissionPage._units.setter import TabSetter, WebPageTabSetter
+from DrissionPage._units.waiter import ChromiumTabWaiter
class ChromiumTab(ChromiumBase):
diff --git a/DrissionPage/session_page.py b/DrissionPage/_pages/session_page.py
similarity index 95%
rename from DrissionPage/session_page.py
rename to DrissionPage/_pages/session_page.py
index 9bf1e1a..846ba9b 100644
--- a/DrissionPage/session_page.py
+++ b/DrissionPage/_pages/session_page.py
@@ -1,336 +1,336 @@
-# -*- coding:utf-8 -*-
-"""
-@Author : g1879
-@Contact : g1879@qq.com
-"""
-from re import search
-from time import sleep
-from urllib.parse import urlparse
-
-from requests import Session
-from requests.structures import CaseInsensitiveDict
-from tldextract import extract
-
-from .base import BasePage
-from .commons.web import cookie_to_dict
-from .configs.session_options import SessionOptions
-from .session_element import SessionElement, make_session_ele
-from .setter import SessionPageSetter
-
-
-class SessionPage(BasePage):
- """SessionPage封装了页面操作的常用功能,使用requests来获取、解析网页"""
-
- def __init__(self, session_or_options=None, timeout=None):
- """
- :param session_or_options: Session对象或SessionOptions对象
- :param timeout: 连接超时时间,为None时从ini文件读取
- """
- super(SessionPage, SessionPage).__init__(self)
- self._response = None
- self._session = None
- self._set = None
- self._s_set_start_options(session_or_options, None)
- self._s_set_runtime_settings()
- self._create_session()
- if timeout is not None:
- self.timeout = timeout
-
- def _s_set_start_options(self, session_or_options, none):
- """启动配置
- :param session_or_options: Session、SessionOptions
- :param none: 用于后代继承
- :return: None
- """
- if not session_or_options or isinstance(session_or_options, SessionOptions):
- self._session_options = session_or_options or SessionOptions(session_or_options)
-
- elif isinstance(session_or_options, Session):
- self._session_options = SessionOptions()
- self._session = session_or_options
-
- def _s_set_runtime_settings(self):
- """设置运行时用到的属性"""
- self._timeout = self._session_options.timeout
- self._download_path = self._session_options.download_path
-
- def _create_session(self):
- """创建内建Session对象"""
- if not self._session:
- self._session = self._session_options.make_session()
-
- def __call__(self, loc_or_str, timeout=None):
- """在内部查找元素
- 例:ele2 = ele1('@id=ele_id')
- :param loc_or_str: 元素的定位信息,可以是loc元组,或查询字符串
- :param timeout: 不起实际作用,用于和ChromiumElement对应,便于无差别调用
- :return: SessionElement对象或属性文本
- """
- return self.ele(loc_or_str)
-
- # -----------------共有属性和方法-------------------
- @property
- def title(self):
- """返回网页title"""
- ele = self._ele('xpath://title', raise_err=False)
- return ele.text if ele else None
-
- @property
- def url(self):
- """返回当前访问url"""
- return self._url
-
- @property
- def _session_url(self):
- """返回当前访问url"""
- return self._url
-
- @property
- def html(self):
- """返回页面的html文本"""
- return self.response.text if self.response else ''
-
- @property
- def json(self):
- """当返回内容是json格式时,返回对应的字典,非json格式时返回None"""
- try:
- return self.response.json()
- except Exception:
- return None
-
- @property
- def user_agent(self):
- """返回user agent"""
- return self.session.headers.get('user-agent', '')
-
- @property
- def session(self):
- """返回session对象"""
- return self._session
-
- @property
- def response(self):
- """返回访问url得到的response对象"""
- return self._response
-
- @property
- def set(self):
- """返回用于等待的对象"""
- if self._set is None:
- self._set = SessionPageSetter(self)
- return self._set
-
- def get(self, url, show_errmsg=False, retry=None, interval=None, timeout=None, **kwargs):
- """用get方式跳转到url
- :param url: 目标url
- :param show_errmsg: 是否显示和抛出异常
- :param retry: 重试次数
- :param interval: 重试间隔(秒)
- :param timeout: 连接超时时间(秒)
- :param kwargs: 连接参数
- :return: url是否可用
- """
- return self._s_connect(url, 'get', None, show_errmsg, retry, interval, **kwargs)
-
- def ele(self, loc_or_ele, timeout=None):
- """返回页面中符合条件的第一个元素、属性或节点文本
- :param loc_or_ele: 元素的定位信息,可以是元素对象,loc元组,或查询字符串
- :param timeout: 不起实际作用,用于和ChromiumElement对应,便于无差别调用
- :return: SessionElement对象或属性、文本
- """
- return self._ele(loc_or_ele)
-
- def eles(self, loc_or_str, timeout=None):
- """返回页面中所有符合条件的元素、属性或节点文本
- :param loc_or_str: 元素的定位信息,可以是loc元组,或查询字符串
- :param timeout: 不起实际作用,用于和ChromiumElement对应,便于无差别调用
- :return: SessionElement对象或属性、文本组成的列表
- """
- return self._ele(loc_or_str, single=False)
-
- def s_ele(self, loc_or_ele=None):
- """返回页面中符合条件的第一个元素、属性或节点文本
- :param loc_or_ele: 元素的定位信息,可以是元素对象,loc元组,或查询字符串
- :return: SessionElement对象或属性、文本
- """
- return make_session_ele(self.html) if loc_or_ele is None else self._ele(loc_or_ele)
-
- def s_eles(self, loc_or_str):
- """返回页面中符合条件的所有元素、属性或节点文本
- :param loc_or_str: 元素的定位信息,可以是元素对象,loc元组,或查询字符串
- :return: SessionElement对象或属性、文本
- """
- return self._ele(loc_or_str, single=False)
-
- def _find_elements(self, loc_or_ele, timeout=None, single=True, raise_err=None):
- """返回页面中符合条件的元素、属性或节点文本,默认返回第一个
- :param loc_or_ele: 元素的定位信息,可以是元素对象,loc元组,或查询字符串
- :param timeout: 不起实际作用,用于和父类对应
- :param single: True则返回第一个,False则返回全部
- :param raise_err: 找不到元素是是否抛出异常,为None时根据全局设置
- :return: SessionElement对象
- """
- return loc_or_ele if isinstance(loc_or_ele, SessionElement) else make_session_ele(self, loc_or_ele, single)
-
- def get_cookies(self, as_dict=False, all_domains=False, all_info=False):
- """返回cookies
- :param as_dict: 是否以字典方式返回,False则以list返回
- :param all_domains: 是否返回所有域的cookies
- :param all_info: 是否返回所有信息,False则只返回name、value、domain
- :return: cookies信息
- """
- if all_domains:
- cookies = self.session.cookies
- else:
- if self.url:
- ex_url = extract(self._session_url)
- domain = f'{ex_url.domain}.{ex_url.suffix}' if ex_url.suffix else ex_url.domain
-
- cookies = tuple(x for x in self.session.cookies if domain in x.domain or x.domain == '')
- else:
- cookies = tuple(x for x in self.session.cookies)
-
- if as_dict:
- return {x.name: x.value for x in cookies}
- elif all_info:
- return [cookie_to_dict(cookie) for cookie in cookies]
- else:
- r = []
- for c in cookies:
- c = cookie_to_dict(c)
- r.append({'name': c['name'], 'value': c['value'], 'domain': c['domain']})
- return r
-
- def post(self, url, data=None, show_errmsg=False, retry=None, interval=None, **kwargs):
- """用post方式跳转到url
- :param url: 目标url
- :param data: 提交的数据
- :param show_errmsg: 是否显示和抛出异常
- :param retry: 重试次数
- :param interval: 重试间隔(秒)
- :param kwargs: 连接参数
- :return: url是否可用
- """
- return self._s_connect(url, 'post', data, show_errmsg, retry, interval, **kwargs)
-
- def _s_connect(self, url, mode, data=None, show_errmsg=False, retry=None, interval=None, **kwargs):
- """执行get或post连接
- :param url: 目标url
- :param mode: 'get' 或 'post'
- :param data: 提交的数据
- :param show_errmsg: 是否显示和抛出异常
- :param retry: 重试次数
- :param interval: 重试间隔(秒)
- :param kwargs: 连接参数
- :return: url是否可用
- """
- retry, interval = self._before_connect(url, retry, interval)
- self._response, info = self._make_response(self._url, mode, data, retry, interval, show_errmsg, **kwargs)
-
- if self._response is None:
- self._url_available = False
-
- else:
- if self._response.ok:
- self._url_available = True
-
- else:
- if show_errmsg:
- raise ConnectionError(f'状态码:{self._response.status_code}.')
- self._url_available = False
-
- return self._url_available
-
- def _make_response(self, url, mode='get', data=None, retry=None, interval=None, show_errmsg=False, **kwargs):
- """生成Response对象
- :param url: 目标url
- :param mode: 'get' 或 'post'
- :param data: post方式要提交的数据
- :param show_errmsg: 是否显示和抛出异常
- :param kwargs: 其它参数
- :return: tuple,第一位为Response或None,第二位为出错信息或'Success'
- """
- kwargs = CaseInsensitiveDict(kwargs)
- if 'headers' not in kwargs:
- kwargs['headers'] = {}
- else:
- kwargs['headers'] = CaseInsensitiveDict(kwargs['headers'])
-
- # 设置referer和host值
- parsed_url = urlparse(url)
- hostname = parsed_url.hostname
- scheme = parsed_url.scheme
- if not check_headers(kwargs, self.session.headers, 'Referer'):
- kwargs['headers']['Referer'] = self.url if self.url else f'{scheme}://{hostname}'
- if 'Host' not in kwargs['headers']:
- kwargs['headers']['Host'] = hostname
-
- if not check_headers(kwargs, self.session.headers, 'timeout'):
- kwargs['timeout'] = self.timeout
-
- r = err = None
- retry = retry if retry is not None else self.retry_times
- interval = interval if interval is not None else self.retry_interval
- for i in range(retry + 1):
- try:
- if mode == 'get':
- r = self.session.get(url, **kwargs)
- elif mode == 'post':
- r = self.session.post(url, data=data, **kwargs)
-
- if r:
- return set_charset(r), 'Success'
-
- except Exception as e:
- err = e
-
- # if r and r.status_code in (403, 404):
- # break
-
- if i < retry:
- sleep(interval)
- if show_errmsg:
- print(f'重试 {url}')
-
- if r is None:
- if show_errmsg:
- if err:
- raise err
- else:
- raise ConnectionError('连接失败')
- return None, '连接失败' if err is None else err
-
- if not r.ok:
- if show_errmsg:
- raise ConnectionError(f'状态码:{r.status_code}')
- return r, f'状态码:{r.status_code}'
-
-
-def check_headers(kwargs, headers, arg):
- """检查kwargs或headers中是否有arg所示属性"""
- return arg in kwargs['headers'] or arg in headers
-
-
-def set_charset(response):
- """设置Response对象的编码"""
- # 在headers中获取编码
- content_type = response.headers.get('content-type', '').lower()
- if not content_type.endswith(';'):
- content_type += ';'
- charset = search(r'charset[=: ]*(.*)?;?', content_type)
-
- if charset:
- response.encoding = charset.group(1)
-
- # 在headers中获取不到编码,且如果是网页
- elif content_type.replace(' ', '').startswith('text/html'):
- re_result = search(b']+).*?>', response.content)
-
- if re_result:
- charset = re_result.group(1).decode()
- else:
- charset = response.apparent_encoding
-
- response.encoding = charset
-
- return response
+# -*- coding:utf-8 -*-
+"""
+@Author : g1879
+@Contact : g1879@qq.com
+"""
+from re import search
+from time import sleep
+from urllib.parse import urlparse
+
+from requests import Session
+from requests.structures import CaseInsensitiveDict
+from tldextract import extract
+
+from DrissionPage._base.base import BasePage
+from DrissionPage._commons.web import cookie_to_dict
+from DrissionPage._configs.session_options import SessionOptions
+from DrissionPage._elements.session_element import SessionElement, make_session_ele
+from DrissionPage._units.setter import SessionPageSetter
+
+
+class SessionPage(BasePage):
+ """SessionPage封装了页面操作的常用功能,使用requests来获取、解析网页"""
+
+ def __init__(self, session_or_options=None, timeout=None):
+ """
+ :param session_or_options: Session对象或SessionOptions对象
+ :param timeout: 连接超时时间,为None时从ini文件读取
+ """
+ super(SessionPage, SessionPage).__init__(self)
+ self._response = None
+ self._session = None
+ self._set = None
+ self._s_set_start_options(session_or_options, None)
+ self._s_set_runtime_settings()
+ self._create_session()
+ if timeout is not None:
+ self.timeout = timeout
+
+ def _s_set_start_options(self, session_or_options, none):
+ """启动配置
+ :param session_or_options: Session、SessionOptions
+ :param none: 用于后代继承
+ :return: None
+ """
+ if not session_or_options or isinstance(session_or_options, SessionOptions):
+ self._session_options = session_or_options or SessionOptions(session_or_options)
+
+ elif isinstance(session_or_options, Session):
+ self._session_options = SessionOptions()
+ self._session = session_or_options
+
+ def _s_set_runtime_settings(self):
+ """设置运行时用到的属性"""
+ self._timeout = self._session_options.timeout
+ self._download_path = self._session_options.download_path
+
+ def _create_session(self):
+ """创建内建Session对象"""
+ if not self._session:
+ self._session = self._session_options.make_session()
+
+ def __call__(self, loc_or_str, timeout=None):
+ """在内部查找元素
+ 例:ele2 = ele1('@id=ele_id')
+ :param loc_or_str: 元素的定位信息,可以是loc元组,或查询字符串
+ :param timeout: 不起实际作用,用于和ChromiumElement对应,便于无差别调用
+ :return: SessionElement对象或属性文本
+ """
+ return self.ele(loc_or_str)
+
+ # -----------------共有属性和方法-------------------
+ @property
+ def title(self):
+ """返回网页title"""
+ ele = self._ele('xpath://title', raise_err=False)
+ return ele.text if ele else None
+
+ @property
+ def url(self):
+ """返回当前访问url"""
+ return self._url
+
+ @property
+ def _session_url(self):
+ """返回当前访问url"""
+ return self._url
+
+ @property
+ def html(self):
+ """返回页面的html文本"""
+ return self.response.text if self.response else ''
+
+ @property
+ def json(self):
+ """当返回内容是json格式时,返回对应的字典,非json格式时返回None"""
+ try:
+ return self.response.json()
+ except Exception:
+ return None
+
+ @property
+ def user_agent(self):
+ """返回user agent"""
+ return self.session.headers.get('user-agent', '')
+
+ @property
+ def session(self):
+ """返回session对象"""
+ return self._session
+
+ @property
+ def response(self):
+ """返回访问url得到的response对象"""
+ return self._response
+
+ @property
+ def set(self):
+ """返回用于等待的对象"""
+ if self._set is None:
+ self._set = SessionPageSetter(self)
+ return self._set
+
+ def get(self, url, show_errmsg=False, retry=None, interval=None, timeout=None, **kwargs):
+ """用get方式跳转到url
+ :param url: 目标url
+ :param show_errmsg: 是否显示和抛出异常
+ :param retry: 重试次数
+ :param interval: 重试间隔(秒)
+ :param timeout: 连接超时时间(秒)
+ :param kwargs: 连接参数
+ :return: url是否可用
+ """
+ return self._s_connect(url, 'get', None, show_errmsg, retry, interval, **kwargs)
+
+ def ele(self, loc_or_ele, timeout=None):
+ """返回页面中符合条件的第一个元素、属性或节点文本
+ :param loc_or_ele: 元素的定位信息,可以是元素对象,loc元组,或查询字符串
+ :param timeout: 不起实际作用,用于和ChromiumElement对应,便于无差别调用
+ :return: SessionElement对象或属性、文本
+ """
+ return self._ele(loc_or_ele)
+
+ def eles(self, loc_or_str, timeout=None):
+ """返回页面中所有符合条件的元素、属性或节点文本
+ :param loc_or_str: 元素的定位信息,可以是loc元组,或查询字符串
+ :param timeout: 不起实际作用,用于和ChromiumElement对应,便于无差别调用
+ :return: SessionElement对象或属性、文本组成的列表
+ """
+ return self._ele(loc_or_str, single=False)
+
+ def s_ele(self, loc_or_ele=None):
+ """返回页面中符合条件的第一个元素、属性或节点文本
+ :param loc_or_ele: 元素的定位信息,可以是元素对象,loc元组,或查询字符串
+ :return: SessionElement对象或属性、文本
+ """
+ return make_session_ele(self.html) if loc_or_ele is None else self._ele(loc_or_ele)
+
+ def s_eles(self, loc_or_str):
+ """返回页面中符合条件的所有元素、属性或节点文本
+ :param loc_or_str: 元素的定位信息,可以是元素对象,loc元组,或查询字符串
+ :return: SessionElement对象或属性、文本
+ """
+ return self._ele(loc_or_str, single=False)
+
+ def _find_elements(self, loc_or_ele, timeout=None, single=True, raise_err=None):
+ """返回页面中符合条件的元素、属性或节点文本,默认返回第一个
+ :param loc_or_ele: 元素的定位信息,可以是元素对象,loc元组,或查询字符串
+ :param timeout: 不起实际作用,用于和父类对应
+ :param single: True则返回第一个,False则返回全部
+ :param raise_err: 找不到元素是是否抛出异常,为None时根据全局设置
+ :return: SessionElement对象
+ """
+ return loc_or_ele if isinstance(loc_or_ele, SessionElement) else make_session_ele(self, loc_or_ele, single)
+
+ def get_cookies(self, as_dict=False, all_domains=False, all_info=False):
+ """返回cookies
+ :param as_dict: 是否以字典方式返回,False则以list返回
+ :param all_domains: 是否返回所有域的cookies
+ :param all_info: 是否返回所有信息,False则只返回name、value、domain
+ :return: cookies信息
+ """
+ if all_domains:
+ cookies = self.session.cookies
+ else:
+ if self.url:
+ ex_url = extract(self._session_url)
+ domain = f'{ex_url.domain}.{ex_url.suffix}' if ex_url.suffix else ex_url.domain
+
+ cookies = tuple(x for x in self.session.cookies if domain in x.domain or x.domain == '')
+ else:
+ cookies = tuple(x for x in self.session.cookies)
+
+ if as_dict:
+ return {x.name: x.value for x in cookies}
+ elif all_info:
+ return [cookie_to_dict(cookie) for cookie in cookies]
+ else:
+ r = []
+ for c in cookies:
+ c = cookie_to_dict(c)
+ r.append({'name': c['name'], 'value': c['value'], 'domain': c['domain']})
+ return r
+
+ def post(self, url, data=None, show_errmsg=False, retry=None, interval=None, **kwargs):
+ """用post方式跳转到url
+ :param url: 目标url
+ :param data: 提交的数据
+ :param show_errmsg: 是否显示和抛出异常
+ :param retry: 重试次数
+ :param interval: 重试间隔(秒)
+ :param kwargs: 连接参数
+ :return: url是否可用
+ """
+ return self._s_connect(url, 'post', data, show_errmsg, retry, interval, **kwargs)
+
+ def _s_connect(self, url, mode, data=None, show_errmsg=False, retry=None, interval=None, **kwargs):
+ """执行get或post连接
+ :param url: 目标url
+ :param mode: 'get' 或 'post'
+ :param data: 提交的数据
+ :param show_errmsg: 是否显示和抛出异常
+ :param retry: 重试次数
+ :param interval: 重试间隔(秒)
+ :param kwargs: 连接参数
+ :return: url是否可用
+ """
+ retry, interval = self._before_connect(url, retry, interval)
+ self._response, info = self._make_response(self._url, mode, data, retry, interval, show_errmsg, **kwargs)
+
+ if self._response is None:
+ self._url_available = False
+
+ else:
+ if self._response.ok:
+ self._url_available = True
+
+ else:
+ if show_errmsg:
+ raise ConnectionError(f'状态码:{self._response.status_code}.')
+ self._url_available = False
+
+ return self._url_available
+
+ def _make_response(self, url, mode='get', data=None, retry=None, interval=None, show_errmsg=False, **kwargs):
+ """生成Response对象
+ :param url: 目标url
+ :param mode: 'get' 或 'post'
+ :param data: post方式要提交的数据
+ :param show_errmsg: 是否显示和抛出异常
+ :param kwargs: 其它参数
+ :return: tuple,第一位为Response或None,第二位为出错信息或'Success'
+ """
+ kwargs = CaseInsensitiveDict(kwargs)
+ if 'headers' not in kwargs:
+ kwargs['headers'] = {}
+ else:
+ kwargs['headers'] = CaseInsensitiveDict(kwargs['headers'])
+
+ # 设置referer和host值
+ parsed_url = urlparse(url)
+ hostname = parsed_url.hostname
+ scheme = parsed_url.scheme
+ if not check_headers(kwargs, self.session.headers, 'Referer'):
+ kwargs['headers']['Referer'] = self.url if self.url else f'{scheme}://{hostname}'
+ if 'Host' not in kwargs['headers']:
+ kwargs['headers']['Host'] = hostname
+
+ if not check_headers(kwargs, self.session.headers, 'timeout'):
+ kwargs['timeout'] = self.timeout
+
+ r = err = None
+ retry = retry if retry is not None else self.retry_times
+ interval = interval if interval is not None else self.retry_interval
+ for i in range(retry + 1):
+ try:
+ if mode == 'get':
+ r = self.session.get(url, **kwargs)
+ elif mode == 'post':
+ r = self.session.post(url, data=data, **kwargs)
+
+ if r:
+ return set_charset(r), 'Success'
+
+ except Exception as e:
+ err = e
+
+ # if r and r.status_code in (403, 404):
+ # break
+
+ if i < retry:
+ sleep(interval)
+ if show_errmsg:
+ print(f'重试 {url}')
+
+ if r is None:
+ if show_errmsg:
+ if err:
+ raise err
+ else:
+ raise ConnectionError('连接失败')
+ return None, '连接失败' if err is None else err
+
+ if not r.ok:
+ if show_errmsg:
+ raise ConnectionError(f'状态码:{r.status_code}')
+ return r, f'状态码:{r.status_code}'
+
+
+def check_headers(kwargs, headers, arg):
+ """检查kwargs或headers中是否有arg所示属性"""
+ return arg in kwargs['headers'] or arg in headers
+
+
+def set_charset(response):
+ """设置Response对象的编码"""
+ # 在headers中获取编码
+ content_type = response.headers.get('content-type', '').lower()
+ if not content_type.endswith(';'):
+ content_type += ';'
+ charset = search(r'charset[=: ]*(.*)?;?', content_type)
+
+ if charset:
+ response.encoding = charset.group(1)
+
+ # 在headers中获取不到编码,且如果是网页
+ elif content_type.replace(' ', '').startswith('text/html'):
+ re_result = search(b']+).*?>', response.content)
+
+ if re_result:
+ charset = re_result.group(1).decode()
+ else:
+ charset = response.apparent_encoding
+
+ response.encoding = charset
+
+ return response
diff --git a/DrissionPage/session_page.pyi b/DrissionPage/_pages/session_page.pyi
similarity index 94%
rename from DrissionPage/session_page.pyi
rename to DrissionPage/_pages/session_page.pyi
index 76bba05..145f122 100644
--- a/DrissionPage/session_page.pyi
+++ b/DrissionPage/_pages/session_page.pyi
@@ -8,11 +8,11 @@ from typing import Any, Union, Tuple, List
from requests import Session, Response
from requests.structures import CaseInsensitiveDict
-from .base import BasePage
-from .commons.constants import NoneElement
-from .configs.session_options import SessionOptions
-from .session_element import SessionElement
-from .setter import SessionPageSetter
+from DrissionPage._base.base import BasePage
+from DrissionPage._commons.constants import NoneElement
+from DrissionPage._configs.session_options import SessionOptions
+from DrissionPage._elements.session_element import SessionElement
+from DrissionPage._units.setter import SessionPageSetter
class SessionPage(BasePage):
diff --git a/DrissionPage/web_page.py b/DrissionPage/_pages/web_page.py
similarity index 97%
rename from DrissionPage/web_page.py
rename to DrissionPage/_pages/web_page.py
index 05dd9f5..058ad99 100644
--- a/DrissionPage/web_page.py
+++ b/DrissionPage/_pages/web_page.py
@@ -3,13 +3,13 @@
@Author : g1879
@Contact : g1879@qq.com
"""
-from .base import BasePage
-from .chromium_page import ChromiumPage
-from .chromium_tab import WebPageTab
-from .commons.web import set_session_cookies, set_browser_cookies
-from .configs.chromium_options import ChromiumOptions
+from DrissionPage._base.base import BasePage
+from DrissionPage._commons.web import set_session_cookies, set_browser_cookies
+from DrissionPage._configs.chromium_options import ChromiumOptions
+from DrissionPage._pages.chromium_page import ChromiumPage
+from DrissionPage._pages.chromium_tab import WebPageTab
+from DrissionPage._units.setter import WebPageSetter
from .session_page import SessionPage
-from .setter import WebPageSetter
class WebPage(SessionPage, ChromiumPage, BasePage):
diff --git a/DrissionPage/web_page.pyi b/DrissionPage/_pages/web_page.pyi
similarity index 94%
rename from DrissionPage/web_page.pyi
rename to DrissionPage/_pages/web_page.pyi
index a70dc0e..de706f9 100644
--- a/DrissionPage/web_page.pyi
+++ b/DrissionPage/_pages/web_page.pyi
@@ -5,20 +5,19 @@
"""
from typing import Union, Tuple, List, Any
-from DownloadKit import DownloadKit
from requests import Session, Response
-from .base import BasePage
-from .chromium_driver import ChromiumDriver
-from .chromium_element import ChromiumElement
+from ._base import BasePage
+from ._chromium_driver import ChromiumDriver
+from ._chromium_element import ChromiumElement
from .chromium_frame import ChromiumFrame
from .chromium_page import ChromiumPage
from .chromium_tab import WebPageTab
-from .configs.chromium_options import ChromiumOptions
-from .configs.session_options import SessionOptions
-from .session_element import SessionElement
+from ._configs.chromium_options import ChromiumOptions
+from ._configs.session_options import SessionOptions
+from ._session_element import SessionElement
from .session_page import SessionPage
-from .setter import WebPageSetter
+from ._units.setter import WebPageSetter
class WebPage(SessionPage, ChromiumPage, BasePage):
diff --git a/DrissionPage/action_chains.py b/DrissionPage/_units/action_chains.py
similarity index 98%
rename from DrissionPage/action_chains.py
rename to DrissionPage/_units/action_chains.py
index 0b5724a..fd733ce 100644
--- a/DrissionPage/action_chains.py
+++ b/DrissionPage/_units/action_chains.py
@@ -5,8 +5,8 @@
"""
from time import sleep
-from .commons.keys import modifierBit, keyDescriptionForString
-from .commons.web import location_in_viewport
+from DrissionPage._commons.keys import modifierBit, keyDescriptionForString
+from DrissionPage._commons.web import location_in_viewport
class ActionChains:
diff --git a/DrissionPage/action_chains.pyi b/DrissionPage/_units/action_chains.pyi
similarity index 92%
rename from DrissionPage/action_chains.pyi
rename to DrissionPage/_units/action_chains.pyi
index ca6061a..83163dd 100644
--- a/DrissionPage/action_chains.pyi
+++ b/DrissionPage/_units/action_chains.pyi
@@ -5,10 +5,9 @@
"""
from typing import Union, Tuple
-from .chromium_base import ChromiumBase
-from .chromium_driver import ChromiumDriver
-from .chromium_element import ChromiumElement
-from .chromium_page import ChromiumPage
+from DrissionPage._base.chromium_driver import ChromiumDriver
+from DrissionPage._elements.chromium_element import ChromiumElement
+from DrissionPage._pages.chromium_base import ChromiumBase
class ActionChains:
diff --git a/DrissionPage/browser_download_manager.py b/DrissionPage/_units/browser_download_manager.py
similarity index 99%
rename from DrissionPage/browser_download_manager.py
rename to DrissionPage/_units/browser_download_manager.py
index 2d6cba5..546076d 100644
--- a/DrissionPage/browser_download_manager.py
+++ b/DrissionPage/_units/browser_download_manager.py
@@ -4,7 +4,7 @@ from pathlib import Path
from shutil import move
from time import sleep, perf_counter
-from .commons.tools import get_usable_path
+from DrissionPage._commons.tools import get_usable_path
class BrowserDownloadManager(object):
diff --git a/DrissionPage/browser_download_manager.pyi b/DrissionPage/_units/browser_download_manager.pyi
similarity index 95%
rename from DrissionPage/browser_download_manager.pyi
rename to DrissionPage/_units/browser_download_manager.pyi
index 6a9a434..0d4b266 100644
--- a/DrissionPage/browser_download_manager.pyi
+++ b/DrissionPage/_units/browser_download_manager.pyi
@@ -1,8 +1,8 @@
from pathlib import Path
from typing import Dict, Optional, Union
-from .browser import Browser
-from .chromium_page import ChromiumPage
+from DrissionPage._base.browser import Browser
+from DrissionPage._pages.chromium_page import ChromiumPage
class BrowserDownloadManager(object):
diff --git a/DrissionPage/network_listener.py b/DrissionPage/_units/network_listener.py
similarity index 99%
rename from DrissionPage/network_listener.py
rename to DrissionPage/_units/network_listener.py
index ee11c08..220b0d0 100644
--- a/DrissionPage/network_listener.py
+++ b/DrissionPage/_units/network_listener.py
@@ -1,4 +1,8 @@
# -*- coding:utf-8 -*-
+"""
+@Author : g1879
+@Contact : g1879@qq.com
+"""
from base64 import b64decode
from json import JSONDecodeError, loads
from queue import Queue
@@ -8,7 +12,7 @@ from time import perf_counter, sleep
from requests.structures import CaseInsensitiveDict
-from .errors import CDPError
+from DrissionPage.errors import CDPError
class NetworkListener(object):
diff --git a/DrissionPage/network_listener.pyi b/DrissionPage/_units/network_listener.pyi
similarity index 95%
rename from DrissionPage/network_listener.pyi
rename to DrissionPage/_units/network_listener.pyi
index 76c5e72..3472032 100644
--- a/DrissionPage/network_listener.pyi
+++ b/DrissionPage/_units/network_listener.pyi
@@ -1,10 +1,15 @@
+# -*- coding:utf-8 -*-
+"""
+@Author : g1879
+@Contact : g1879@qq.com
+"""
from queue import Queue
from typing import Union, Dict, List, Iterable, Tuple
from requests.structures import CaseInsensitiveDict
-from chromium_base import ChromiumBase
-from chromium_driver import ChromiumDriver
+from DrissionPage._base.chromium_driver import ChromiumDriver
+from DrissionPage._pages.chromium_base import ChromiumBase
class NetworkListener(object):
diff --git a/DrissionPage/setter.py b/DrissionPage/_units/setter.py
similarity index 99%
rename from DrissionPage/setter.py
rename to DrissionPage/_units/setter.py
index 3decfca..94f2262 100644
--- a/DrissionPage/setter.py
+++ b/DrissionPage/_units/setter.py
@@ -7,8 +7,8 @@ from pathlib import Path
from requests.structures import CaseInsensitiveDict
-from .commons.tools import show_or_hide_browser
-from .commons.web import set_browser_cookies, set_session_cookies
+from DrissionPage._commons.tools import show_or_hide_browser
+from DrissionPage._commons.web import set_browser_cookies, set_session_cookies
class ChromiumBaseSetter(object):
diff --git a/DrissionPage/setter.pyi b/DrissionPage/_units/setter.pyi
similarity index 92%
rename from DrissionPage/setter.pyi
rename to DrissionPage/_units/setter.pyi
index 0ed4134..994ad87 100644
--- a/DrissionPage/setter.pyi
+++ b/DrissionPage/_units/setter.pyi
@@ -11,13 +11,13 @@ from requests.adapters import HTTPAdapter
from requests.auth import HTTPBasicAuth
from requests.cookies import RequestsCookieJar
-from .chromium_base import ChromiumBase, ChromiumPageScroll
-from .chromium_element import ChromiumElement
-from .chromium_frame import ChromiumFrame
-from .chromium_page import ChromiumPage
-from .chromium_tab import ChromiumTab
-from .session_page import SessionPage
-from .web_page import WebPage
+from DrissionPage._elements.chromium_element import ChromiumElement
+from DrissionPage._pages.chromium_base import ChromiumBase, ChromiumPageScroll
+from DrissionPage._pages.chromium_frame import ChromiumFrame
+from DrissionPage._pages.chromium_page import ChromiumPage
+from DrissionPage._pages.chromium_tab import ChromiumTab
+from DrissionPage._pages.session_page import SessionPage
+from DrissionPage._pages.web_page import WebPage
FILE_EXISTS = Literal['skip', 'rename', 'overwrite', 's', 'r', 'o']
diff --git a/DrissionPage/waiter.py b/DrissionPage/_units/waiter.py
similarity index 99%
rename from DrissionPage/waiter.py
rename to DrissionPage/_units/waiter.py
index 71dfc46..06a98f8 100644
--- a/DrissionPage/waiter.py
+++ b/DrissionPage/_units/waiter.py
@@ -1,8 +1,8 @@
# -*- coding:utf-8 -*-
from time import sleep, perf_counter
-from .commons.constants import Settings
-from .errors import WaitTimeoutError
+from DrissionPage._commons.constants import Settings
+from DrissionPage.errors import WaitTimeoutError
class ChromiumBaseWaiter(object):
diff --git a/DrissionPage/waiter.pyi b/DrissionPage/_units/waiter.pyi
similarity index 93%
rename from DrissionPage/waiter.pyi
rename to DrissionPage/_units/waiter.pyi
index 823ee3b..a05a921 100644
--- a/DrissionPage/waiter.pyi
+++ b/DrissionPage/_units/waiter.pyi
@@ -5,11 +5,11 @@
"""
from typing import Union
+from DrissionPage._elements.chromium_element import ChromiumElement
+from DrissionPage._pages.chromium_base import ChromiumBase
+from DrissionPage._pages.chromium_frame import ChromiumFrame
+from DrissionPage._pages.chromium_page import ChromiumPage
from .browser_download_manager import DownloadMission
-from .chromium_base import ChromiumBase
-from .chromium_element import ChromiumElement
-from .chromium_frame import ChromiumFrame
-from .chromium_page import ChromiumPage
class ChromiumBaseWaiter(object):
diff --git a/DrissionPage/common.py b/DrissionPage/common.py
index f1225cc..2c67c17 100644
--- a/DrissionPage/common.py
+++ b/DrissionPage/common.py
@@ -6,9 +6,9 @@
"""
from FlowViewer import Listener, RequestMan
-from .session_element import make_session_ele
+from ._elements.session_element import make_session_ele
-from .action_chains import ActionChains
-from .commons.keys import Keys
-from .commons.by import By
-from .commons.constants import Settings
+from ._units.action_chains import ActionChains
+from ._commons.keys import Keys
+from ._commons.by import By
+from ._commons.constants import Settings
diff --git a/DrissionPage/common.pyi b/DrissionPage/common.pyi
index 54677db..f1d57c4 100644
--- a/DrissionPage/common.pyi
+++ b/DrissionPage/common.pyi
@@ -1,7 +1,10 @@
# -*- coding:utf-8 -*-
-from .session_element import make_session_ele as make_session_ele
-
-from .action_chains import ActionChains as ActionChains
-from .commons.keys import Keys as Keys
-from .commons.by import By as By
-from .commons.constants import Settings as Settings
+"""
+@Author : g1879
+@Contact : g1879@qq.com
+"""
+from ._commons.by import By as By
+from ._commons.constants import Settings as Settings
+from ._commons.keys import Keys as Keys
+from ._elements.session_element import make_session_ele as make_session_ele
+from ._units.action_chains import ActionChains as ActionChains
diff --git a/DrissionPage/easy_set.py b/DrissionPage/easy_set.py
index 7ed75a7..c70cb68 100644
--- a/DrissionPage/easy_set.py
+++ b/DrissionPage/easy_set.py
@@ -7,8 +7,8 @@ from os import popen
from pathlib import Path
from re import search
-from .configs.chromium_options import ChromiumOptions
-from .configs.options_manage import OptionsManager
+from ._configs.chromium_options import ChromiumOptions
+from ._configs.options_manage import OptionsManager
def configs_to_here(save_name=None):
diff --git a/DrissionPage/errors.py b/DrissionPage/errors.py
index 7bab148..589fb95 100644
--- a/DrissionPage/errors.py
+++ b/DrissionPage/errors.py
@@ -1,4 +1,8 @@
# -*- coding:utf-8 -*-
+"""
+@Author : g1879
+@Contact : g1879@qq.com
+"""
class BaseError(Exception):