国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

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

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

瀏覽:95日期: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亚洲精品久久频 | 亚洲天堂一区在线 | 成人亚洲精品一区二区 | 2022久久免费精品国产72精品 | 毛片a区| 看色网站 | 巨乳激情| 99精品视频在线观看免费播放 | 欧美大尺度xxxxx视频 | 欧美性色网 | 精品国产精品国产 | 国产亚洲精品一区二区在线观看 | 亚洲一区二区在线 | 午夜影院黄色 | 亚洲图片一区二区三区 | 色天使色婷婷在线影院亚洲 | 成人国产三级在线播放 | 国产观看在线 | 亚洲欧美色视频 | 午夜爽爽爽 | 亚洲另类激情综合偷自拍 | 亚洲精品中文字幕一区在线 | 国产日韩美国成人 | 中文字幕亚洲 综合久久 | 亚洲精品99久久一区二区三区 | 欧美一级毛片免费观看视频 | 男女精品视频 | 日韩国产在线观看 | 欧美成年视频 | 久久99精品久久久久久h | 美国免费三片在线观看 | 成人免费小视频 | 日韩特级片 | 99精品视频在线这里只有 | 鸥美毛片 | 99视频国产热精品视频 | 国产成人黄色 | 一级特黄a免费大片 | 特级a欧美孕妇做爰片毛片 特级a欧美做爰片毛片 | 一级毛片免费播放视频 |