Python下载文件

操作文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
import os
import shutil
from datetime import datetime
from urllib.request
from requests

downloadUrl = 'https://alist.qyide.com'
fileFullPath = 'd:/23.png'
urllib.request.urlretrieve(downloadUrl, filename=fileFullPath)
# 或者
file = requests.get(downloadUrl, allow_redirects=True, headers={
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36'
})
open(fileFullPath, 'wb').write(file.content)

本文地址: https://github.com/maxzhao-it/blog/post/6071409/