mirror of
https://gitee.com/g1879/DrissionPage.git
synced 2024-12-10 04:00:23 +08:00
完善download路径,修复路径为.\时的bug。
_make_response函数中self._url改成self.url,确保d模式download时url正确。
This commit is contained in:
parent
28d065d4ff
commit
d41069c2a6
@ -170,6 +170,10 @@ class SessionPage(object):
|
||||
for key, i in enumerate(goal_Path.parts): # 去除路径中的非法字符
|
||||
goal_path += goal_Path.drive if key == 0 and goal_Path.drive else re.sub(r'[*:|<>?"]', '', i).strip()
|
||||
goal_path += '\\' if i != '\\' and key < len(goal_Path.parts) - 1 else ''
|
||||
|
||||
goal_Path = Path(goal_path)
|
||||
goal_Path.mkdir(parents=True, exist_ok=True)
|
||||
goal_path = goal_Path.absolute()
|
||||
full_path = Path(f'{goal_path}\\{full_name}')
|
||||
|
||||
if full_path.exists():
|
||||
@ -183,8 +187,6 @@ class SessionPage(object):
|
||||
else:
|
||||
raise ValueError("Argument file_exists can only be 'skip', 'overwrite', 'rename'.")
|
||||
|
||||
Path(goal_path).mkdir(parents=True, exist_ok=True)
|
||||
|
||||
if show_msg: # 打印要下载的文件
|
||||
print(full_name if file_name == full_name else f'{file_name} -> {full_name}')
|
||||
print(f'Downloading to: {goal_path}')
|
||||
@ -233,14 +235,14 @@ class SessionPage(object):
|
||||
kwargs_set = set(x.lower() for x in kwargs)
|
||||
if 'headers' in kwargs_set:
|
||||
header_set = set(x.lower() for x in kwargs['headers'])
|
||||
if self._url and 'referer' not in header_set:
|
||||
kwargs['headers']['Referer'] = self._url
|
||||
if self.url and 'referer' not in header_set:
|
||||
kwargs['headers']['Referer'] = self.url
|
||||
if 'host' not in header_set:
|
||||
kwargs['headers']['Host'] = urlparse(url).hostname
|
||||
else:
|
||||
kwargs['headers'] = self.session.headers
|
||||
kwargs['headers']['Host'] = urlparse(url).hostname
|
||||
if self._url:
|
||||
if self.url:
|
||||
kwargs['headers']['Referer'] = self._url
|
||||
|
||||
if 'timeout' not in kwargs_set:
|
||||
|
Loading…
x
Reference in New Issue
Block a user