【新三板年报文本分析】第二辑:从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)
相关推荐
郭老二3 小时前
【Python】基本语法:装饰器语法糖@
python
_Jimmy_4 小时前
Agent常用检索器的详细介绍
python·langchain
小柯南敲键盘5 小时前
图片翻译API接入与自动化实现指南
运维·python·自动化
旅僧5 小时前
Q-learning(自用)
python·机器学习
Python大数据分析@5 小时前
曝梁文锋称「一度不想维护C端用户,奈何赶不走」,DeepSeek真不需要C端用户吗?可能会有啥影响吗?
python
艾斯特_7 小时前
工作流与多Agent协作:LangGraph、MCP和A2A的应用分层
人工智能·python·ai
IT小盘7 小时前
04-大模型流式输出原理-SSE与Python实现
开发语言·网络·人工智能·python
我叫黑大帅7 小时前
add()和 __add__() 写法哪个更好呢?
后端·python·面试
不如语冰7 小时前
AI大模型入门-Python进阶-上下文管理与with语句
开发语言·数据结构·数据库·人工智能·pytorch·redis·python
柠檬味的Cat7 小时前
GEO优化系统哪个渠道商好
大数据·人工智能·python