4.1.0.0b24修复host和referer一个设置问题;优化注释

This commit is contained in:
g1879 2024-09-12 14:49:17 +08:00
parent e54171710b
commit 78d3b90653
6 changed files with 19 additions and 11 deletions

View File

@ -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'

View File

@ -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 = ...

View File

@ -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 = {}

View File

@ -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: 查找元素超时时间默认与页面等待时间一致

View File

@ -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

View File

@ -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: 查找元素超时时间默认与页面等待时间一致