ChromiumPage增加browser_version;DataPacket.request增加cookies属性;修复动作链wait()问题

This commit is contained in:
g1879 2024-03-19 21:50:26 +08:00
parent cfed80e196
commit 4cdf08aa8f
5 changed files with 27 additions and 7 deletions

View File

@ -71,8 +71,9 @@ class ChromiumPage(ChromiumBase):
def _run_browser(self):
"""连接浏览器"""
self._browser = Browser(self._chromium_options.address, self._browser_id, self)
if (self._is_exist and self._chromium_options._headless is False and
'headless' in self._browser.run_cdp('Browser.getVersion')['userAgent'].lower()):
r = self._browser.run_cdp('Browser.getVersion')
self._browser_version = r['product']
if self._is_exist and self._chromium_options._headless is False and 'headless' in r['userAgent'].lower():
self._browser.quit(3)
connect_browser(self._chromium_options)
ws = get(f'http://{self._chromium_options.address}/json/version', headers={'Connection': 'close'})
@ -140,6 +141,11 @@ class ChromiumPage(ChromiumBase):
"""返回浏览器进程id"""
return self.browser.process_id
@property
def browser_version(self):
"""返回所控制的浏览器版本号"""
return self._browser_version
def save(self, path=None, name=None, as_pdf=False, **kwargs):
"""把当前页面保存为文件如果path和name参数都为None只返回文本
:param path: 保存路径为None且name不为None时保存在当前路径

View File

@ -37,6 +37,7 @@ class ChromiumPage(ChromiumBase):
self._rect: Optional[TabRect] = ...
self._is_exist: bool = ...
self._lock: Lock = ...
self._browser_version: str = ...
def _handle_options(self, addr_or_opts: Union[str, ChromiumOptions]) -> str: ...
@ -62,6 +63,9 @@ class ChromiumPage(ChromiumBase):
@property
def process_id(self) -> Optional[int]: ...
@property
def browser_version(self) -> str: ...
@property
def set(self) -> ChromiumPageSetter: ...

View File

@ -305,6 +305,7 @@ class Actions:
:return: None
"""
self.owner.wait(second=second, scope=scope)
return self
def _get_key_data(self, key, action):
"""获取用于发送的按键信息

View File

@ -528,8 +528,14 @@ class Request(object):
self._postData = postData
return self._postData
@property
def cookies(self):
"""以list形式返回发送的cookies"""
return [c['cookie'] for c in self.extra_info.associatedCookies if not c['blockedReasons']]
@property
def extra_info(self):
"""返回额外数据"""
return RequestExtraInfo(self._data_packet._request_extra_info or {})

View File

@ -62,6 +62,11 @@ class Listener(object):
fit_count: bool = True,
raise_err: bool = None) -> Union[List[DataPacket], DataPacket, None]: ...
def steps(self,
count: int = None,
timeout: float = None,
gap=1) -> Iterable[Union[DataPacket, List[DataPacket]]]: ...
@property
def results(self) -> Union[DataPacket, Dict[str, List[DataPacket]], False]: ...
@ -83,11 +88,6 @@ class Listener(object):
def _loading_failed(self, **kwargs) -> None: ...
def steps(self,
count: int = None,
timeout: float = None,
gap=1) -> Iterable[Union[DataPacket, List[DataPacket]]]: ...
def _set_callback(self) -> None: ...
@ -174,6 +174,9 @@ class Request(object):
@property
def postData(self) -> Any: ...
@property
def cookies(self) -> List[dict]: ...
@property
def extra_info(self) -> Optional[RequestExtraInfo]: ...