【新三板年报文本分析】第二辑:从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)
相关推荐
zzwq.3 分钟前
Pandas读取数据:csv、excel、sql全攻略
python·pandas
飞Link4 分钟前
LangGraph SDK 全量技术手册:分布式 Agent 集群的远程调用与编排引擎
开发语言·分布式·python·数据挖掘
迷藏4944 分钟前
**基于Python与OpenCV的光场显示图像处理技术实践**在现代显示技术发展中,**光场显示(Light
java·图像处理·python·opencv
枫叶林FYL6 分钟前
【Python高级工程与架构实战】项目六:RAG知识库问答系统(企业文档智能)
python·深度学习·机器学习
witAI11 分钟前
gpt写小说工具2025推荐,助力高效创作小说
人工智能·python·gpt
Roselind_Yi12 分钟前
【开源仓库系列学习分享】MemPalace 仓库(超级记忆管家)全流程部署!(专业版)
人工智能·经验分享·笔记·python·数据挖掘·github·知识图谱
Flying pigs~~14 分钟前
检索增强生成RAG项目tools_04:flask➕fastapi➕高并发
数据库·python·flask·大模型·fastapi·异步
JACK的服务器笔记16 分钟前
《服务器测试百日学习计划——Day19:PCIe自动检测脚本,用Python把lspci设备清点标准化》
服务器·python·学习
YJlio20 分钟前
Sysinternals实战教程专栏介绍:这不是一本到此为止的书,而是一套看穿 Windows 的排障方法
windows·python·电脑·outlook·windows部署·eixv3·pe装机
好运的阿财22 分钟前
OpenClaw工具拆解之 sessions_list+sessions_history
人工智能·python·程序人生·ai·ai编程·openclaw