【新三板年报文本分析】第二辑:从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)
相关推荐
XiaoMaqqqq15 分钟前
目前知名的IP驱动产业新场景新工具有哪些
网络·python·网络协议·tcp/ip
玩大数据的龙威22 分钟前
农经权二轮延包—固定比例尺不定图幅的公示图批量生成
python·arcgis·二轮延包公示图
虎虎(_ _)。゜zzZ2 小时前
关于字典中的解包问题
python
全栈弄潮儿²⁰²⁴2 小时前
Python实战第2期: 变量与数据类型
python·变量·数据类型·python实战
程序员yu2 小时前
会编网络:别被入门教程骗了,Python实用能力不在语法本身
开发语言·python·学习·算法
鬼手点金2 小时前
opencode组件详解-安装方式
人工智能·python·优化器·分析器·nanogpt
Bruce_Liuxiaowei3 小时前
Python 字典默认值完全指南:从 KeyError 到 defaultdict
开发语言·数据结构·python·字典
数据杂坛3 小时前
【Python程序开发系列】一文搞清楚Gunicorn以及和Nginx的区别
python·nginx·gunicorn
zjh9005303 小时前
Visual C++ 2010 安装使用完整包:高手秘籍
python
Allen_LVyingbo3 小时前
信息化部门在AI时代的编程转移路径分析(上)
人工智能·python·算法·健康医疗·数据库开发·时序数据库·数据库架构