微调下载功能

This commit is contained in:
g1879 2023-01-22 00:05:52 +08:00
parent 3b09e69d43
commit 28b81f7be2
4 changed files with 8 additions and 4 deletions

View File

@ -421,7 +421,7 @@ class ChromiumDownloadSetter(DownloadSetter):
self._page.run_cdp('Page.setDownloadBehavior', behavior='allow', downloadPath=path, not_change=True)
if self._page._download_kit is not None:
self._page._download_kit.goal_path = path
self._page.download.goal_path = path
def use_browser(self):
"""设置使用浏览器下载文件"""

View File

@ -28,6 +28,7 @@ class SessionPage(BasePage):
"""
self._response = None
self._download_kit = None
self._download_set = None
self._create_session(session_or_options)
timeout = timeout if timeout is not None else self.timeout
super().__init__(timeout)
@ -126,7 +127,9 @@ class SessionPage(BasePage):
@property
def download_set(self):
"""返回用于设置下载参数的对象"""
return DownloadSetter(self)
if self._download_set is None:
self._download_set = DownloadSetter(self)
return self._download_set
def get(self, url, show_errmsg=False, retry=None, interval=None, timeout=None, **kwargs):
"""用get方式跳转到url
@ -340,7 +343,7 @@ class DownloadSetter(object):
path = path if path is None else str(path)
self._page._download_path = path
if self._page._download_kit is not None:
self._page._download_kit.goal_path = path
self._page.download.goal_path = path
def check_headers(kwargs, headers, arg) -> bool:

View File

@ -26,6 +26,7 @@ class SessionPage(BasePage):
self._response: Response = ...
self._download_path: str = ...
self._download_kit: DownloadKit = ...
self._download_set: DownloadSetter = ...
self._url_available: bool = ...
self.timeout: float = ...
self.retry_times: int = ...

View File

@ -499,7 +499,7 @@ class WebPageDownloadSetter(ChromiumDownloadSetter):
self._page._download_path = path
if self._page._download_kit is not None:
self._page._download_kit.goal_path = path
self._page.download.goal_path = path
if self._page._has_driver:
try: