diff --git a/DrissionPage/__init__.py b/DrissionPage/__init__.py index 315c249..e76efce 100644 --- a/DrissionPage/__init__.py +++ b/DrissionPage/__init__.py @@ -12,4 +12,4 @@ from ._pages.chromium_page import ChromiumPage from ._pages.session_page import SessionPage from ._pages.web_page import WebPage -__version__ = '4.1.0.0b23' +__version__ = '4.1.0.0b24' diff --git a/DrissionPage/_functions/elements.pyi b/DrissionPage/_functions/elements.pyi index c7ae7e2..854548f 100644 --- a/DrissionPage/_functions/elements.pyi +++ b/DrissionPage/_functions/elements.pyi @@ -27,6 +27,10 @@ class SessionElementsList(list): """ ... + def __next__(self) -> SessionElement: ... + + def __getitem__(self, _i) -> SessionElement: ... + @property def get(self) -> Getter: """返回用于属性的对象""" @@ -42,8 +46,6 @@ class SessionElementsList(list): """用于筛选单个元素的对象""" ... - def __next__(self) -> SessionElement: ... - class ChromiumElementsList(SessionElementsList): _owner: ChromiumBase = ... @@ -57,6 +59,10 @@ class ChromiumElementsList(SessionElementsList): """ ... + def __next__(self) -> ChromiumElement: ... + + def __getitem__(self, _i) -> ChromiumElement: ... + @property def filter(self) -> ChromiumFilter: """返回用于筛选多个元素的对象""" @@ -113,8 +119,6 @@ class ChromiumElementsList(SessionElementsList): """ ... - def __next__(self) -> ChromiumElement: ... - class SessionFilterOne(object): _list: SessionElementsList = ... diff --git a/DrissionPage/_functions/web.py b/DrissionPage/_functions/web.py index 387b73e..d6061b7 100644 --- a/DrissionPage/_functions/web.py +++ b/DrissionPage/_functions/web.py @@ -304,7 +304,7 @@ def format_headers(txt): for k, v in txt.items(): if k in (':method', ':scheme', ':authority', ':path'): txt.pop(k) - else: + elif v not in (None, False, True): txt[k] = str(v) return txt headers = {} diff --git a/DrissionPage/_pages/mix_tab.pyi b/DrissionPage/_pages/mix_tab.pyi index 5c9d6be..abba2a9 100644 --- a/DrissionPage/_pages/mix_tab.pyi +++ b/DrissionPage/_pages/mix_tab.pyi @@ -215,7 +215,7 @@ class MixTab(SessionPage, ChromiumTab): def eles(self, locator: Union[Tuple[str, str], str], - timeout: float = None) -> Union[SessionElementsList, ChromiumElementsList]: + timeout: float = None) -> ChromiumElementsList: """返回页面中所有符合条件的元素、属性或节点文本 :param locator: 元素的定位信息,可以是loc元组,或查询字符串 :param timeout: 查找元素超时时间(秒),默认与页面等待时间一致 diff --git a/DrissionPage/_pages/session_page.py b/DrissionPage/_pages/session_page.py index 12f7bab..3bb48e3 100644 --- a/DrissionPage/_pages/session_page.py +++ b/DrissionPage/_pages/session_page.py @@ -197,10 +197,10 @@ class SessionPage(BasePage): def _make_response(self, url, mode='get', retry=None, interval=None, show_errmsg=False, **kwargs): kwargs = CaseInsensitiveDict(kwargs) - if 'headers' not in kwargs: - kwargs['headers'] = CaseInsensitiveDict() - else: + if 'headers' in kwargs: kwargs['headers'] = CaseInsensitiveDict(format_headers(kwargs['headers'])) + else: + kwargs['headers'] = CaseInsensitiveDict() # 设置referer和host值 parsed_url = urlparse(url) @@ -208,8 +208,12 @@ class SessionPage(BasePage): scheme = parsed_url.scheme if not check_headers(kwargs['headers'], self._headers, 'Referer'): kwargs['headers']['Referer'] = self.url if self.url else f'{scheme}://{hostname}' + elif not kwargs['headers']['Referer']: + kwargs['headers'].pop('Referer') if not check_headers(kwargs['headers'], self._headers, 'Host'): kwargs['headers']['Host'] = hostname + elif not kwargs['headers']['Host']: + kwargs['headers'].pop('Host') if not check_headers(kwargs, self._headers, 'timeout'): kwargs['timeout'] = self.timeout diff --git a/DrissionPage/_pages/web_page.pyi b/DrissionPage/_pages/web_page.pyi index 1ad05a9..a688ccd 100644 --- a/DrissionPage/_pages/web_page.pyi +++ b/DrissionPage/_pages/web_page.pyi @@ -230,7 +230,7 @@ class WebPage(SessionPage, ChromiumPage, BasePage): def eles(self, locator: Union[Tuple[str, str], str], - timeout: float = None) -> Union[SessionElementsList, ChromiumElementsList]: + timeout: float = None) -> ChromiumElementsList: """返回页面中所有符合条件的元素、属性或节点文本 :param locator: 元素的定位信息,可以是loc元组,或查询字符串 :param timeout: 查找元素超时时间(秒),默认与页面等待时间一致