Python使用PycURL发送HTTP请求示例代码

2024-06-21 21:28:28 2025-01-01 09:06:23 李腾 30 次阅读 0 次点赞

官方网站:PycURL Home Page

示例代码

import pycurl
import certifi
from io import BytesIO

def download(url, file_path):
    buffer = BytesIO()
    c = pycurl.Curl()
    c.setopt(c.HTTP_VERSION, c.CURL_HTTP_VERSION_1_0)
    c.setopt(c.URL, url.encode("utf-8"))
    c.setopt(c.WRITEDATA, buffer)
    c.setopt(c.CAINFO, certifi.where())
    c.perform()
    c.close()
    body = buffer.getvalue()
    file = open(file_path, "wb")
    file.write(body)
    file.close()

本文由人工编写,AI优化,请仔细甄别,转载请注明转自www.hylab.cn,原文地址:Python使用PycURL发送HTTP请求示例代码

评论 (0)

登录后发表评论

暂无评论,快来发表第一条评论吧!