Python Wget : Check for duplicate files and skip if it exists?

标签 python wget

所以我正在使用 WGET 下载文件,我想在下载之前检查文件是否存在。我知道 CLI 版本有一个选项:(see example) .

# check if file exsists
# if not, download
wget.download(url, path)

使用 WGET,它无需命名即可下载文件。这很重要,因为我不想在文件已有名称时重命名它们。

如果有其他文件下载方法可以检查现有文件,请告诉我!谢谢!!!

最佳答案

wget.download() 没有任何这样的选项。以下解决方法应该可以解决问题:

import subprocess

url = "https://url/to/index.html"
path = "/path/to/save/your/files"
subprocess.run(["wget", "-r", "-nc", "-P", path, url])

如果文件已经存在,您将收到以下消息:

File ‘index.html’ already there; not retrieving.

编辑: 如果您在 Windows 上运行它,您还必须包含 shell=True:

subprocess.run(["wget", "-r", "-nc", "-P", path, url], shell=True)

关于Python Wget : Check for duplicate files and skip if it exists?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55524747/

相关文章:

php - 使用 PHP/Python 下载 url 中的特定文件

wget 不适用于 Google 云端硬盘中的共享文件

mysql - 如何制作 wget 和 mysql bash 脚本

Javascript 到 "export"所有 cookies?

python - 了解如何通过 Python 使用 Google API 客户端库

python - 使用 Selenium 从网站提取 SSL 证书详细信息 - Chrome 驱动程序

python - 字典排序的时间复杂度

python - 鹈鹕—— 'articles_page' 未定义

python - 如何使用flask.jsonify 通过查询数据库返回嵌套的json?

php - 从 exec() 或 shell_exec() 调用时 wget 不工作