4.1.0.9优化下载逻辑

This commit is contained in:
g1879 2024-10-17 17:35:50 +08:00
parent e2653ed3b0
commit e4e1affd43
8 changed files with 20 additions and 8 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.8'
__version__ = '4.1.0.9'

View File

@ -296,7 +296,7 @@ class BasePage(BaseParser):
if self._DownloadKit is None:
if not self._session:
self._create_session()
self._DownloadKit = DownloadKit(driver=self, goal_path=self.download_path)
self._DownloadKit = DownloadKit(driver=self, save_path=self.download_path)
return self._DownloadKit
def _before_connect(self, url, retry, interval):

View File

@ -96,6 +96,10 @@ class ChromiumPage(ChromiumBase):
def address(self):
return self.browser.address
@property
def download_path(self):
return self.browser.download_path
def save(self, path=None, name=None, as_pdf=False, **kwargs):
return save_page(self, path, name, as_pdf, kwargs)

View File

@ -112,6 +112,10 @@ class WebPage(SessionPage, ChromiumPage, BasePage):
def timeout(self):
return self.timeouts.base if self._d_mode else self._timeout
@property
def download_path(self):
return self.browser.download_path
def get(self, url, show_errmsg=False, retry=None, interval=None, timeout=None, **kwargs):
if self._d_mode:
return super(SessionPage, self).get(url, show_errmsg, retry, interval, timeout)

View File

@ -125,7 +125,7 @@ class Clicker(object):
if not self._ele.tab._browser._dl_mgr._running:
self._ele.tab._browser.set.download_path('.')
if new_tab:
if new_tab or self._ele.tab._type.endswith('Page'):
obj = browser = self._ele.tab._browser
tid = 'browser'
t_settings = TabDownloadSettings(self._ele.owner.tab_id)

View File

@ -51,7 +51,7 @@ class SessionPageSetter(BaseSetter):
def download_path(self, path):
super().download_path(path)
if self._owner._DownloadKit:
self._owner._DownloadKit.set.goal_path(self._owner._download_path)
self._owner._DownloadKit.set.save_path(self._owner._download_path)
def timeout(self, second):
self._owner._timeout = second
@ -230,7 +230,7 @@ class TabSetter(ChromiumBaseSetter):
super().download_path(path)
self._owner.browser._dl_mgr.set_path(self._owner, self._owner._download_path)
if self._owner._DownloadKit:
self._owner._DownloadKit.set.goal_path(self._owner._download_path)
self._owner._DownloadKit.set.save_path(self._owner._download_path)
def download_file_name(self, name=None, suffix=None):
self._owner.browser._dl_mgr.set_rename(self._owner.tab_id, name, suffix)
@ -263,8 +263,12 @@ class ChromiumPageSetter(TabSetter):
self._owner.browser.retry_interval = interval
def download_path(self, path):
super().download_path(path)
if path is None:
path = '.'
self._owner._download_path = str(Path(path).absolute())
self._owner.browser.set.download_path(path)
if self._owner._DownloadKit:
self._owner._DownloadKit.set.save_path(path)
def download_file_name(self, name=None, suffix=None):
self._owner.browser.set.download_file_name(name, suffix)

View File

@ -1,7 +1,7 @@
requests
lxml
cssselect
DownloadKit>=2.0.4
DownloadKit>=2.0.5
websocket-client
click
tldextract

View File

@ -23,7 +23,7 @@ setup(
'lxml',
'requests',
'cssselect',
'DownloadKit>=2.0.4',
'DownloadKit>=2.0.5',
'websocket-client',
'click',
'tldextract',