前言
- 技术栈
Python 3.11.8
httpx 0.28.1
示例代码
# encoding: utf-8
# author: qbit
# date: 2025-06-30
# summary: httpx 使用代理下载文件
import httpx
proxy = 'http://127.0.0.1:8081'
def DownFile(url, file):
with open(file, 'wb') as f:
with httpx.stream('GET', url, proxy=proxy) as response:
for chunk in response.iter_bytes():
f.write(chunk)
print(f"文件已保存为 {file}")
url = 'http://qbit.cn/part-00000.gz'
file = './part-00000.gz'
DownFile(url, file)
相关阅读
本文出自 qbit snap
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。