【发布时间】:2020-06-25 07:23:59
【问题描述】:
我有一个装满 pdf 文件的文件夹。我需要根据给定的条件遍历每个 pdf 文件。使用熊猫是不可能的。有没有什么方法可以使用 pdfplumber 遍历每个文件?
import os
import glob
import shutil
import pandas as pd
import plotly.express as px
import xlrd
import matplotlib.pyplot as plt
%matplotlib inline
import time
from datetime import datetime
from pytz import timezone
import numpy as np
from tabula import read_pdf
import tabula
import requests
import pdfplumber
from tabula import read_pdf
glob.glob("C:/Users/Dreamer/Desktop/test_run/machine/*.pdf")
#THIS IS THE CONDITION I WANT TO IMPLEMENT IN EACH FILE
with pdfplumber.open(path) as pdf:
page = pdf.pages[0]
text = page.extract_text()
for row in text.split('\n'):
if row.startswith('Raumtemperatur '):
jobstart = row.split()[-2]
jobend = row.split()[-1]
print("jobstart", jobstart)
print("jobstart", jobend)
期待解决方案或替代方案:)
【问题讨论】:
-
通过遍历 glob 到 with 块的路径来传递 pdf_path?
-
是的,对该文件夹中的每个 pdf 文件使用“with”块逻辑 :)