【新三板年报文本分析】第二辑:从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)
相关推荐
zhangfeng11337 分钟前
PowerShell 中不支持激活你选中的 Python 虚拟环境,建议切换到命令提示符(Command Prompt)
开发语言·python·prompt
qh0526wy11 分钟前
WINDOWS BAT 开机登录后自动启动
windows·python
程序员哈基耄19 分钟前
浏览器文件格式转换工具:简单、安全、高效的文本与数据处理助手
python·安全·数据挖掘
FL162386312929 分钟前
基于yolov8的无人机视角夜间车辆检测识别系统python源码+onnx模型+评估指标曲线+精美GUI界面
python·yolo·无人机
GIS之路34 分钟前
GDAL 实现影像裁剪
前端·python·arcgis·信息可视化
大飞记Python1 小时前
代码级教程|用Playwright实现Web自动化测试:从零到录制生成脚本
自动化测试·python·selenium·playwright
_WndProc1 小时前
【Python】方程计算器
开发语言·python
我的offer在哪里1 小时前
技术实战:用 Python 脚本高效采集与分析手机操作日志
开发语言·python·智能手机
智航GIS1 小时前
11.18 自定义Pandas扩展开发指南:打造你的专属数据分析武器库
python·数据分析·pandas
AI_56781 小时前
测试用例“标准化”:TestRail实战技巧,从“用例编写”到“测试报告生成”
java·python·测试用例·testrail