【新三板年报文本分析】第二辑:从pdf链接的列表中批量下载年报文件

第一辑中已经获取了新三板年报的pdf链接,使用request库进行批量下载。

send_headers为requests的headers,不需要做变动。

在for循环中读取每一行数据的链接数据,创建一个空pdf,将链接指向的pdf文件写入空pdf文件。

for循环内容可以根据个人需求更改for循环里的内容。

python 复制代码
#引用 requests文件
import requests
import pandas as pd
import time

year=2018
stage='创新层'
dataPath='nianbaoURL33968.csv'
df=pd.read_csv(dataPath)

send_headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36",
"Connection": "keep-alive",
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
"Accept-Language": "zh-CN,zh;q=0.8"}
  
for i in range(33968):
    if df['year'][i]==year and df['stage'][i]==stage:
        address=df['url'][i]
        f=requests.get(address, headers=send_headers ,stream=True, timeout=20)
        fileName='data\\'+str(year)+stage+'\\'+str(i+1)+'_'+str(df['year'][i])+df['firm'][i]+'.pdf'
        with open(fileName, "wb") as file:
            file.write(f.content)
            file.close()
        print('序号'+str(i+1)+':'+df['firm'][i]+'完成')
        time.sleep(0.25)
相关推荐
努力变大白4 分钟前
ReAct Agent 创建:tools 协议与文本 ReAct 双路线实践
python·agent·react框架
vipxieliang11 分钟前
Python 面向对象编程:类、继承、多态与组合
python
Nuanyt12 分钟前
Agent 学习笔记(下篇二):Claude Code 生态、RAG 与 Memory(Stage 5–6)
笔记·python·memory·rag·aiagent·claude code·agentskill
用户2986985301414 分钟前
Python 实战:Markdown 转 PDF 的代码实现与页面设置
python·api·markdown
thusloop15 分钟前
零门槛接入 GPT-6-astra 与 claude-opus-5-5,三大场景实战指南
python·gpt·算法·agent·claude·codex
程序猿乐锅26 分钟前
Streamlit 实现 AI 聊天 Agent:角色提示词、流式输出与会话管理
开发语言·前端·笔记·后端·python·学习
小南知更鸟30 分钟前
【2026 年 Python 包管理工具选型:从“工具崇拜”回到工程约束】
开发语言·python
TomEval36 分钟前
【测AI】第20篇:大模型安全测试 —— 越狱攻击与防护
人工智能·python·功能测试·ai·aigc·测试用例·安全性测试
RuoyiOffice1 小时前
达梦 DM8 + openGauss:RuoYi Office 的 MySQL 数据转换与导入实践
数据库·spring boot·python·sql·信创
用户0332126663671 小时前
轻松使用 Python 将 RTF 转换为 Word 文档(含批量转换与格式互转)
python