每天努力一点点,坚持下去 ------ 博客首页

如何在接口中下载PDF

Py文件

import time
import requests

# 拼接headers数据
headers = {
    'Content-Type':'application/x-msdownload;charset=UTF-8',
    }
headers['cl-auth'] = env_dict['Authorization']

url = "http://static.cninfo.com.cn/finalpage/2021-04-17/1209711009.PDF" 
results = requests.post(req_url,json=yaml_case['body'],headers=headers, verify=False)
if results.status_code == 200:
   with open(r"E:\pdf文档\%s.pdf" % name, "wb") as code:
        code.write(results.content)
        time.sleep(5)  # 防止访问速度过快,可以灵活的调整时间

 

posted @ 2022-11-01 14:24  他还在坚持嘛  阅读(71)  评论(0编辑  收藏  举报