你可以使用urllib或requests模块来下载文件。以下是使用urllib模块的示例代码:
import urllib.requesturl = "https://example.com/sample.jpg"filename = "sample.jpg"urllib.request.urlretrieve(url, filename)print("文件已下载")如果你希望使用requests模块来下载文件,可以参考以下示例代码:
import requestsurl = "https://example.com/sample.jpg"filename = "sample.jpg"response = requests.get(url)with open(filename, "wb") as file:file.write(response.content)print("文件已下载")这两种方法都可以用来从URL下载文件,你可以根据自己的偏好选择其中一种。
上一篇:C++中字符串太长怎么换行
下一篇:java高并发场景如何解决
python









