【新三板年报文本分析】第二辑:从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)
相关推荐
Thanks_ks1 小时前
利用 Python 进行股票数据可视化分析
python·matplotlib·热力图·seaborn·可视化分析·股票数据·yfinance
pzx_0012 小时前
【深度学习】自定义实现DataSet和DataLoader
开发语言·人工智能·python·深度学习·算法
起个破名想半天了8 小时前
Sklearn入门之datasets的基本用法
人工智能·python·机器学习·sklearn
大雄野比8 小时前
【scikit-learn基础】--『预处理』之 缺失值处理
python·机器学习·scikit-learn
小鑫仔_x9 小时前
selenium之Token
python·selenium·测试工具
神仙别闹9 小时前
基于Python(Django)+SQLite 实现(Web) 点菜管理系统
python·django·sqlite
Thanks_ks9 小时前
探秘 Python 网络编程:构建简单聊天服务器
python·网络编程·socket·tcp·客户端·套接字·聊天服务器
小羊的 utopia10 小时前
第P10周:Pytorch实现车牌识别
pytorch·python·机器学习
[太阳]8810 小时前
Spark Core
linux·windows·python
意.远11 小时前
使用PyTorch实现目标检测边界框转换与可视化
人工智能·pytorch·python·深度学习·神经网络·目标检测