久久福利_99r_国产日韩在线视频_直接看av的网站_中文欧美日韩_久久一

您的位置:首頁技術文章
文章詳情頁

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

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

問題描述

使用過pypdf 對英文pdf文檔處理比較簡單,但是對中文的支持好像不太好

使用過textract 看文檔支持的格式比較多方法也比較簡單,但是老師出錯

-- coding: utf-8 --

import textractimport pyPdfimport pdf2textimport pdfminerimport chardet

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

這個 出錯是編碼問題-- coding: utf-8 --

import textractimport pyPdfimport pdfminerimport chardet

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

這個出錯類型不清楚

少使用了pdf2text庫,但是出錯情況好像不一樣。

pdfminer庫還沒看過,看著好像麻煩一些, 求解一下解析提取中文的pdf的方法。謝謝

問題解答

回答1:

之前用過的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 編程
相關文章:
主站蜘蛛池模板: 人人人人人你人人人人人 | 久久久久久久久成人 | 久久久国产精品 | 亚洲精品久久久久久久久久久 | 一区二区不卡视频在线观看 | 国产在线精品视频 | 99久久精品国产一区二区成人 | 黄色直接看 | 亚洲性网 | 欧日韩免费 | 欧美日韩中文在线观看 | 精品国产一区一区二区三亚瑟 | 午夜小视频在线观看 | 欧美综合一区 | 亚洲高清免费 | 国产在线视频网 | 天堂中文视频在线观看 | 在线免费观看毛片 | 欧美人体一区二区三区 | 九九99| 亚洲人成人一区二区在线观看 | 伊人激情av一区二区三区 | 日韩一区二区在线观看 | 精品久久久久久久久久久久久久 | 在线观看免费毛片视频 | 四虎成人在线 | 午夜精品久久久久久久久久久久 | 欧美一区二区在线视频 | 欧美另类亚洲 | 日韩国产一区二区三区 | 亚洲精品视频在线看 | 午夜精品久久久久久 | 在线色网| 一区二区在线播放视频 | 精品亚洲一区二区三区在线观看 | 一区二区三区四区免费 | 国产黄色一级大片 | 国产免费拔擦拔擦8x高清在线人 | 蜜臀网 | 欧美亚洲另类在线 | 国产乱人伦av在线a 天天碰天天操 |