動態

詳情 返回 返回

Pthon httpx 使用代理下載文件(qbit) - 動態 詳情

前言

  • 技術棧
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)

相關閲讀

  • httpx 官方文檔:https://www.python-httpx.org/advanced/proxies/
  • Windows 下配置 pproxy 開機啓動
本文出自 qbit snap
user avatar u_14540126 頭像 haoqidedalianmao 頭像 huaiyue_63f0b9e085bf0 頭像 yanyingjie 頭像 hunter_58d48c41761b8 頭像 wayn111 頭像 zhuiyi_5e4ea2134d01e 頭像
點贊 7 用戶, 點贊了這篇動態!
點贊

Add a new 評論

Some HTML is okay.