【发布时间】:2014-04-21 04:08:12
【问题描述】:
我希望使用PDFMiner提取在线可用的pdf文件的内容。
我的代码是基于documentation中可用的代码,用于提取硬盘上PDF文件的内容:
# Open a PDF file.
fp = open('mypdf.pdf', 'rb')
# Create a PDF parser object associated with the file object.
parser = PDFParser(fp)
# Create a PDF document object that stores the document structure.
document = PDFDocument(parser)
稍作改动后效果很好。
现在,我尝试使用urllib2.openurl 获取在线 PDF,但这不起作用。我收到一条错误消息:coercing to Unicode: need string or buffer, instance found。
如何从urllib2.openurl 获取字符串(或其他任何内容),以便在我给它一个 PDF 文件名(而不是 URL)时它与 open 函数相同?
如果我的问题不清楚,请告诉我。
【问题讨论】:
标签: python pdf urllib2 fetch urllib