python爬取pdf内容_Python读取PDF内容

from urllib.request importurlopenfrom pdfminer.pdfinterp importPDFResourceManager, process_pdffrom pdfminer.converter importTextConverterfrom pdfminer.layout importLAParamsfrom io importStringIOfrom io importopendefreadPDF(pdfFile):

rsrcmgr=PDFResourceManager()

retstr=StringIO()

laparams=LAParams()

device= TextConverter(rsrcmgr, retstr, laparams=laparams)

process_pdf(rsrcmgr, device, pdfFile)

device.close()

content=retstr.getvalue()

retstr.close()returncontent

pdfFile= urlopen("http://pythonscraping.com/pages/warandpeace/chapter1.pdf")

outputString=readPDF(pdfFile)print(outputString)

pdfFile.close()

你可能感兴趣的:(python爬取pdf内容)