0
我正在使用Scrapy蜘蛛,试图使用slate从目录中的多个PDF文件中提取文本。我没有兴趣将实际的PDF保存到磁盘,因此我建议查看https://docs.python.org/2/library/io.html#buffered-streams的io.bytesIO子类。创建bytesIO对象
但是我不确定如何将PDF正文传递给bytesIO类,然后传递虚拟PDF文件以获取文本。到目前为止,我有:
class Ove_Spider(BaseSpider):
name = "ove"
allowed_domains = ['myurl.com']
start_urls = ['myurl/hgh/']
def parse(self, response):
for a in response.xpath('//a[@href]/@href'):
link = a.extract()
if link.endswith('.pdf'):
link = urlparse.urljoin(base_url, link)
yield Request(link, callback=self.save_pdf)
def save_pdf(self, response):
in_memory_pdf = BytesIO()
in_memory_pdf.read(response.body) # Trying to read in PDF which is in response body
我越来越:
in_memory_pdf.read(response.body)
TypeError: integer argument expected, got 'str'
我怎样才能得到这个工作?