Creating bytesIO object
<p>I am working on a <a href="https://en.wikipedia.org/wiki/Scrapy" rel="nofollow">Scrapy</a> spider, trying to extract the text from multiple PDF files in a directory, using <a href="https://pypi.python.org/pypi/slate" rel="nofollow">slate</a>. I have no interest in saving the actual PDF to disk, and so I've been advised to look into the io.bytesIO subclass at <a href="https://docs.python.org/2/library/io.html#buffered-streams" rel="nofollow">https://docs.python.org/2/library/io.html#buffered-streams</a>.</p>

<p>However I'm not sure how to pass the PDF body to the bytesIO class and then pass the virtual PDF slate to get the text. So far I have:</p>

<pre><code>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
</code></pre>

<p>I'm getting:</p>

<pre><code>in_memory_pdf.read(response.body)
TypeError: integer argument expected, got 'str'
</code></pre>

<p>How can I get this working?</p>