【新三板年报文本分析】第二辑:从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)
相关推荐
宸翰7 分钟前
Python学习:年轻人的第一个入门Python项目(FastAPI版)
后端·python
AsDuang8 分钟前
Python 3.12 MagicMethods - 55 - __irshift__
开发语言·python
DeepModel39 分钟前
【概率分布】指数分布(Exponential Distribution)原理、推导与实战
python·算法·概率论
波特率1152001 小时前
miniconda入门使用
python·conda·miniconda·python环境
二闹1 小时前
别再死记硬背了!带你扒开*args和**kwargs的底裤
后端·python
m0_743297421 小时前
Python在金融科技(FinTech)中的应用
jvm·数据库·python
老师好,我是刘同学1 小时前
列表推导式详解与实战应用
python
与虾牵手2 小时前
Rust 入门:一个写了 6 年 Python 的人,被编译器骂了三天
python
2401_857865232 小时前
Python日志记录(Logging)最佳实践
jvm·数据库·python
AsDuang2 小时前
Python 3.12 MagicMethods - 54 - __rrshift__
开发语言·python