有支持提取pdf类型文件的python第三方库或是方法吗?,,使用过pypdf 对英文
有支持提取pdf类型文件的python第三方库或是方法吗?,,使用过pypdf 对英文
使用过pypdf 对英文pdf文档处理比较简单,但是对中文的支持好像不太好
使用过textract 看文档支持的格式比较多方法也比较简单,但是老师出错
-- coding: utf-8 --
import textract
import pyPdf
import pdf2text
import pdfminer
import chardet
text = textract.process("F:ll.pdf",method = 'pdfminer')
print text
这个 出错是编码问题
-- coding: utf-8 --
import textract
import pyPdf
import pdfminer
import chardet
text = textract.process("F:ll.pdf",method = 'pdfminer')
print text
这个出错类型不清楚
少使用了pdf2text库,但是出错情况好像不一样。
pdfminer库还没看过,看着好像麻烦一些, 求解一下解析提取中文的pdf的方法。谢谢
之前用过的pdfminer pip install pdfminer
# -*- coding: utf-8 -*-from bs4 import BeautifulSoupimport requestsimport refrom pdfminer.pdfinterp import PDFResourceManager, PDFPageInterpreterfrom pdfminer.converter import TextConverterfrom pdfminer.layout import LAParamsfrom cStringIO import StringIO#from io import StringIO for python3from io import openfrom pdfminer.pdfpage import PDFPagedef pdf_txt(url): rsrcmgr = PDFResourceManager() retstr = StringIO() codec = 'utf-8' laparams = LAParams() device = TextConverter(rsrcmgr, retstr, codec=codec, laparams=laparams) f = requests.get(url).content fp = StringIO(f) interpreter = PDFPageInterpreter(rsrcmgr, device) password = "" maxpages = 0 caching = True pagenos = set() for page in PDFPage.get_pages(fp, pagenos, maxpages=maxpages, password=password, caching=caching, check_extractable=True): interpreter.process_page(page) fp.close() device.close() str = retstr.getvalue() retstr.close() return strtxt=tpdf_txt('http://pythonscraping.com/pages/warandpeace/chapter1.pdf')print txt#如果pdf含有中文,输出到文件#open('pdf.txt','wb').write(txt)python readpdf.py'''CHAPTER I"Well, Prince, so Genoa and Lucca are now just family estates oftheBuonapartes. But I warn you, if you don't tell me that thismeans war,if you still try to defend the infamies and horrorsperpetrated bythat Antichrist- I really believe he is Antichrist- I willhavenothing more to do with you and you are no longer my friend,no longermy 'faithful slave,' as you call yourself! But how do youdo? I seeI have frightened you- sit down and tell me all the news."It was in July, 1805, and the speaker was the well-knownAnnaPavlovna Scherer, maid of honor and favorite of theEmpress MaryaFedorovna. With these words she greeted PrinceVasili Kuragin, a manof high rank and importance, who was thefirst to arrive at herreception. Anna Pavlovna had had a cough forsome days. She was, asshe said, suffering from la grippe; grippebeing then a new word inSt. Petersburg, used only by the elite.All her invitations without exception, written in French,anddelivered by a scarlet-liveried footman that morning, ran as'''
编橙之家文章,
相关内容
- Python怎么将16进制字符串转换成汉字输出呢,python进制
- 想用Python语言完成日志分析工作,请问这样的程序思路
- python爬虫批量爬取糗事百科段子,python糗事,刚学Pytho
- 关于Python字符串中ASCII字符映射的一个小问题,pythona
- lambda在这段代码中起到什么作用,大家帮看下,lambda代码
- pymssql安装正常import却不好用了什么原因,pymssqlimport原
- Python什么方法可以把amr格式转换成mp3格式?,pythonamr,从
- Python在交互模式中调用.py文件中的函数操作方法是怎么
- Python程序运行时查看对象状态怎样设计才能实现,pyt
- Python爬虫IOError问题是字符串问题吗?,pythonioerror,用Py
评论关闭