代码拉取完成,页面将自动刷新
同步操作将从 tingwen/数据分析 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
# This is a sample Python script.
# Press Shift+F10 to execute it or replace it with your code.
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings
import os
import pdfplumber
def parsePDF(pdf_path, txt_path):
try:
with open(txt_path, "w", encoding='utf-8') as txt:
with pdfplumber.open(pdf_path) as pdf:
for i, page in enumerate(pdf.pages):
print(f'正在转换{pdf_path}-{i + 1}页')
txt.write(page.extract_text())
except Exception as e:
print(f"发生异常: {str(e)}")
pdf_dir = '/Users/liujingyu/Downloads/gitee/cipin/3/pdf'
txt_dir = '/Users/liujingyu/Downloads/gitee/cipin/3/txt'
for root, dirs, files in os.walk(pdf_dir):
for file in files:
if file.endswith('.pdf'):
pdf_path = os.path.join(root, file)
relative_path = os.path.relpath(pdf_path, pdf_dir)
txt_path = os.path.join(txt_dir, os.path.splitext(relative_path)[0] + '.txt')
try:
parsePDF(pdf_path, txt_path)
except Exception as e:
with open('错误信息.txt', 'a', encoding='UTF-8', errors='ignore') as f:
f.write(f"{pdf_path}: {str(e)}\n")
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。