色综合图-色综合图片-色综合图片二区150p-色综合图区-玖玖国产精品视频-玖玖香蕉视频

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

文本處理 - 求教使用python庫(kù)提取pdf的方法?

瀏覽:106日期:2022-09-02 11:18:15

問(wèn)題描述

使用過(guò)pypdf 對(duì)英文pdf文檔處理比較簡(jiǎn)單,但是對(duì)中文的支持好像不太好

使用過(guò)textract 看文檔支持的格式比較多方法也比較簡(jiǎn)單,但是老師出錯(cuò)

-- coding: utf-8 --

import textractimport pyPdfimport pdf2textimport pdfminerimport chardet

text = textract.process('F:ll.pdf',method = ’pdfminer’)print text

這個(gè) 出錯(cuò)是編碼問(wèn)題-- coding: utf-8 --

import textractimport pyPdfimport pdfminerimport chardet

text = textract.process('F:ll.pdf',method = ’pdfminer’)print text

這個(gè)出錯(cuò)類型不清楚

少使用了pdf2text庫(kù),但是出錯(cuò)情況好像不一樣。

pdfminer庫(kù)還沒(méi)看過(guò),看著好像麻煩一些, 求解一下解析提取中文的pdf的方法。謝謝

問(wèn)題解答

回答1:

之前用過(guò)的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’’’

標(biāo)簽: Python 編程
相關(guān)文章:
主站蜘蛛池模板: 日韩黄色一级毛片 | 国产成人精品午夜二三区 | 国产特黄特色的大片观看免费视频 | 在线观看亚洲天堂 | a级在线观看视频 | 欧美一区二区三区日韩免费播 | 免费国产不卡午夜福在线 | 国产美女拍拍拍在线观看 | 久久久免费精品视频 | 亚洲欧美日韩天堂 | 久久中文字幕在线观看 | 欧美成人资源 | 一区二区三区免费观看 | 中国美女牲交一级毛片 | 日韩中文字幕免费观看 | 伊人网五月天 | 一级女性黄 色生活片 | 国产在线精品一区二区三区 | 亚洲精品一区二区三区四区 | 国内精品久久久久久影院老狼 | 香港全黄一级毛片在线播放 | 日本一区深夜影院深a | 国产精品三级a三级三级午夜 | 亚洲人免费视频 | 99视频在线精品自拍 | 国产三级精品播放 | 日本三级网站在线线观看 | 成人精品视频在线观看播放 | 国产深夜福利在线观看网站 | 农村寡妇女人一级毛片 | 国产成人高清视频在线观看免费97 | 久久精品久久精品 | 一级国产 | 高清在线一区二区 | 成人免费在线视频网 | 香港全黄一级毛片在线播放 | 国产精品一国产精品免费 | 国产欧美一区二区三区观看 | 九九九热在线精品免费全部 | 免费一级a毛片在线 | 手机看片免费基地你懂的 |