You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用curl或无头Python爬取ffiec.gov新站点银行控股公司FR Y-9C数据

解决方案

失败原因排查

  • 接口路径拼写错误:你之前尝试的链接里用了nwp,正确路径是npw
  • 参数格式错误:zipfilename参数不需要加单引号,你链接里的%27是单引号的URL编码,会导致后台无法匹配到对应文件
  • 缺少来源校验头:站点校验了请求的Referer头,没有携带合法Referer的请求会被直接拒绝

可行curl命令

直接使用以下命令即可下载对应日期的zip包,将命令中的BHCF20210630.ZIP替换为你需要的文件名即可:
curl -O -H "Referer: https://www.ffiec.gov/npw/FinancialReport/FinancialDataDownload" "https://www.ffiec.gov/npw/FinancialReport/ReturnBHCFZipFiles?zipfilename=BHCF20210630.ZIP"
参数说明:

  • -O:直接使用远程文件的文件名作为本地保存文件名
  • -H "Referer: ...":携带合法的来源请求头,通过站点校验

无头Python实现方案

仅需依赖requests库,无需任何浏览器相关工具,适合在Linux服务器上定时执行:

  1. 先安装依赖:
    pip install requests
  2. 示例代码:
import requests
import os

def download_bhcf_zip(date_str: str, save_dir: str = "./") -> bool:
    """
    下载指定日期的BHCF zip包
    :param date_str: 日期字符串,格式为YYYYMMDD,例如20210630
    :param save_dir: 本地保存目录,默认当前目录
    :return: 下载成功返回True,失败返回False
    """
    file_name = f"BHCF{date_str}.ZIP"
    base_url = "https://www.ffiec.gov/npw/FinancialReport/ReturnBHCFZipFiles"
    headers = {
        "Referer": "https://www.ffiec.gov/npw/FinancialReport/FinancialDataDownload",
        "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
    }
    params = {"zipfilename": file_name}
    save_path = os.path.join(save_dir, file_name)

    try:
        resp = requests.get(base_url, headers=headers, params=params, timeout=30, stream=True)
        resp.raise_for_status()
        with open(save_path, "wb") as f:
            for chunk in resp.iter_content(chunk_size=8192):
                if chunk:
                    f.write(chunk)
        return True
    except Exception as e:
        print(f"下载{file_name}失败:{str(e)}")
        if os.path.exists(save_path):
            os.remove(save_path)
        return False

if __name__ == "__main__":
    # 示例:下载2021年6月30日的数据包
    download_bhcf_zip("20210630")

内容的提问来源于stack exchange,提问作者Martien Lubberink

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.05 10:12:02