DrissionPage/docs/使用方法/下载文件.md
2021-12-10 19:02:42 +08:00

23 lines
951 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

selenium 缺乏对浏览器下载文件的有效管理,难以进行检测下载状态、重命名、失败管理。
使用 requests 下载文件能较好实现以上功能,但代码较为繁琐。
因此 DrissionPage 封装了 download 方法,整合了两者优点,可从 selenium 获取登录信息,用 requests 进行下载。
弥补了 selenium 的不足,使下载简洁高效。
## 功能
- 指定下载路径
- 重命名文件,可不填写扩展名,程序自动补充
- 存在同名文件时,可选择重命名、覆盖、跳过等处理方式
- 显示下载进度
- 支持 post 方式
- 支持自定义连接参数
## 演示
```python
url = 'https://www.baidu.com/img/flexible/logo/pc/result.png' # 文件 url
save_path = r'C:\download' # 存放路径
# 重命名为img.png存在重名时自动在文件名末尾加上序号显示下载进度
page.download(url, save_path, 'img', 'rename', show_msg=True)
```