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'
我怎樣才能得到這個工作?