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

2024-06-21 李腾 62 次阅读 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优化,转载请注明原文地址: Python使用PycURL发送HTTP请求示例代码

评论 (0)

登录后发表评论

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