mirror of
https://gitee.com/g1879/DrissionPage.git
synced 2024-12-10 04:00:23 +08:00
4.1.0.0b24修复host和referer一个设置问题;优化注释
This commit is contained in:
parent
e54171710b
commit
78d3b90653
@ -12,4 +12,4 @@ 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.web_page import WebPage
|
||||||
|
|
||||||
__version__ = '4.1.0.0b23'
|
__version__ = '4.1.0.0b24'
|
||||||
|
@ -27,6 +27,10 @@ class SessionElementsList(list):
|
|||||||
"""
|
"""
|
||||||
...
|
...
|
||||||
|
|
||||||
|
def __next__(self) -> SessionElement: ...
|
||||||
|
|
||||||
|
def __getitem__(self, _i) -> SessionElement: ...
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def get(self) -> Getter:
|
def get(self) -> Getter:
|
||||||
"""返回用于属性的对象"""
|
"""返回用于属性的对象"""
|
||||||
@ -42,8 +46,6 @@ class SessionElementsList(list):
|
|||||||
"""用于筛选单个元素的对象"""
|
"""用于筛选单个元素的对象"""
|
||||||
...
|
...
|
||||||
|
|
||||||
def __next__(self) -> SessionElement: ...
|
|
||||||
|
|
||||||
|
|
||||||
class ChromiumElementsList(SessionElementsList):
|
class ChromiumElementsList(SessionElementsList):
|
||||||
_owner: ChromiumBase = ...
|
_owner: ChromiumBase = ...
|
||||||
@ -57,6 +59,10 @@ class ChromiumElementsList(SessionElementsList):
|
|||||||
"""
|
"""
|
||||||
...
|
...
|
||||||
|
|
||||||
|
def __next__(self) -> ChromiumElement: ...
|
||||||
|
|
||||||
|
def __getitem__(self, _i) -> ChromiumElement: ...
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def filter(self) -> ChromiumFilter:
|
def filter(self) -> ChromiumFilter:
|
||||||
"""返回用于筛选多个元素的对象"""
|
"""返回用于筛选多个元素的对象"""
|
||||||
@ -113,8 +119,6 @@ class ChromiumElementsList(SessionElementsList):
|
|||||||
"""
|
"""
|
||||||
...
|
...
|
||||||
|
|
||||||
def __next__(self) -> ChromiumElement: ...
|
|
||||||
|
|
||||||
|
|
||||||
class SessionFilterOne(object):
|
class SessionFilterOne(object):
|
||||||
_list: SessionElementsList = ...
|
_list: SessionElementsList = ...
|
||||||
|
@ -304,7 +304,7 @@ def format_headers(txt):
|
|||||||
for k, v in txt.items():
|
for k, v in txt.items():
|
||||||
if k in (':method', ':scheme', ':authority', ':path'):
|
if k in (':method', ':scheme', ':authority', ':path'):
|
||||||
txt.pop(k)
|
txt.pop(k)
|
||||||
else:
|
elif v not in (None, False, True):
|
||||||
txt[k] = str(v)
|
txt[k] = str(v)
|
||||||
return txt
|
return txt
|
||||||
headers = {}
|
headers = {}
|
||||||
|
@ -215,7 +215,7 @@ class MixTab(SessionPage, ChromiumTab):
|
|||||||
|
|
||||||
def eles(self,
|
def eles(self,
|
||||||
locator: Union[Tuple[str, str], str],
|
locator: Union[Tuple[str, str], str],
|
||||||
timeout: float = None) -> Union[SessionElementsList, ChromiumElementsList]:
|
timeout: float = None) -> ChromiumElementsList:
|
||||||
"""返回页面中所有符合条件的元素、属性或节点文本
|
"""返回页面中所有符合条件的元素、属性或节点文本
|
||||||
:param locator: 元素的定位信息,可以是loc元组,或查询字符串
|
:param locator: 元素的定位信息,可以是loc元组,或查询字符串
|
||||||
:param timeout: 查找元素超时时间(秒),默认与页面等待时间一致
|
:param timeout: 查找元素超时时间(秒),默认与页面等待时间一致
|
||||||
|
@ -197,10 +197,10 @@ class SessionPage(BasePage):
|
|||||||
|
|
||||||
def _make_response(self, url, mode='get', retry=None, interval=None, show_errmsg=False, **kwargs):
|
def _make_response(self, url, mode='get', retry=None, interval=None, show_errmsg=False, **kwargs):
|
||||||
kwargs = CaseInsensitiveDict(kwargs)
|
kwargs = CaseInsensitiveDict(kwargs)
|
||||||
if 'headers' not in kwargs:
|
if 'headers' in kwargs:
|
||||||
kwargs['headers'] = CaseInsensitiveDict()
|
|
||||||
else:
|
|
||||||
kwargs['headers'] = CaseInsensitiveDict(format_headers(kwargs['headers']))
|
kwargs['headers'] = CaseInsensitiveDict(format_headers(kwargs['headers']))
|
||||||
|
else:
|
||||||
|
kwargs['headers'] = CaseInsensitiveDict()
|
||||||
|
|
||||||
# 设置referer和host值
|
# 设置referer和host值
|
||||||
parsed_url = urlparse(url)
|
parsed_url = urlparse(url)
|
||||||
@ -208,8 +208,12 @@ class SessionPage(BasePage):
|
|||||||
scheme = parsed_url.scheme
|
scheme = parsed_url.scheme
|
||||||
if not check_headers(kwargs['headers'], self._headers, 'Referer'):
|
if not check_headers(kwargs['headers'], self._headers, 'Referer'):
|
||||||
kwargs['headers']['Referer'] = self.url if self.url else f'{scheme}://{hostname}'
|
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'):
|
if not check_headers(kwargs['headers'], self._headers, 'Host'):
|
||||||
kwargs['headers']['Host'] = hostname
|
kwargs['headers']['Host'] = hostname
|
||||||
|
elif not kwargs['headers']['Host']:
|
||||||
|
kwargs['headers'].pop('Host')
|
||||||
if not check_headers(kwargs, self._headers, 'timeout'):
|
if not check_headers(kwargs, self._headers, 'timeout'):
|
||||||
kwargs['timeout'] = self.timeout
|
kwargs['timeout'] = self.timeout
|
||||||
|
|
||||||
|
@ -230,7 +230,7 @@ class WebPage(SessionPage, ChromiumPage, BasePage):
|
|||||||
|
|
||||||
def eles(self,
|
def eles(self,
|
||||||
locator: Union[Tuple[str, str], str],
|
locator: Union[Tuple[str, str], str],
|
||||||
timeout: float = None) -> Union[SessionElementsList, ChromiumElementsList]:
|
timeout: float = None) -> ChromiumElementsList:
|
||||||
"""返回页面中所有符合条件的元素、属性或节点文本
|
"""返回页面中所有符合条件的元素、属性或节点文本
|
||||||
:param locator: 元素的定位信息,可以是loc元组,或查询字符串
|
:param locator: 元素的定位信息,可以是loc元组,或查询字符串
|
||||||
:param timeout: 查找元素超时时间(秒),默认与页面等待时间一致
|
:param timeout: 查找元素超时时间(秒),默认与页面等待时间一致
|
||||||
|
Loading…
x
Reference in New Issue
Block a user