我使用PDFminer的pdf2text將PDF縮減爲文本。不幸的是它包含特殊字符。讓我告訴從我的控制檯Python:給我帶來問題的特殊字符(來自PDFminer)
>>>a=pdf_to_text("ap.pdf")
繼承人它的一個樣本,一個小截
>>>a[5000:5500]
'f one architect. Decades ...... but to re\xef\xac\x82ect\none set of design ideas, than to have one that contains many\ngood but independent and uncoordinated ideas.\n1 Joshua Bloch, \xe2\x80\x9cHow to Design a Good API and Why It Matters\xe2\x80\x9d, G......=-3733'
我明白,我必須對其進行編碼
>>>a[5000:5500].encode('utf-8')
Traceback (most recent call last):
File "<interactive input>", line 1, in <module>
UnicodeDecodeError: 'ascii' codec can't decode byte 0xef in position 237: ordinal not in range(128)
我搜索了一下週圍和輸出試過了,特別是Replace special characters in python。輸入來自PDFminer,所以它很難控制(AFAIK)。從這個輸出中產生適當的明文的方法是什麼?
我在做什麼錯?
--a快速修復:改變PDFminer的編解碼器ascii-,但它不是一個持久的solution--
--Abandoned快速的答案 - 改變編解碼器修復刪除信息 -
由馬克西姆 http://en.wikipedia.org/wiki/Windows-1251提到--a relavent主題 -
感謝這個問題! Im初學者在Python中,你可能會張貼一個演示代碼如何使用Pdfminer,以便這個錯誤不裝飾器?謝謝 –