title: Working with a pdf from the web directly in Python?
body: <p>I'm trying to use Python to read .pdf files from the web directly rather than save them all to my computer.  All I need is the text from the .pdf and I'm going to be reading a lot (~60k) of them, so I'd prefer to not actually have to save them all.</p>
  
  <p>I know how to save a .pdf from the internet using urllib and open it with PyPDF2. (<a href="https://stackoverflow.com/questions/9751197/opening-pdf-urls-with-pypdf">example</a>)</p>
  
  <p>I want to skip the saving-to-file step.</p>
  
  <pre><code>import urllib, PyPDF2
  urllib.urlopen('https://bitcoin.org/bitcoin.pdf')
  wFile = urllib.urlopen('https://bitcoin.org/bitcoin.pdf')
  lFile = PyPDF2.pdf.PdfFileReader(wFile.read())
  </code></pre>
  
  <p>I get an error that is fairly easy to understand:</p>
  
  <pre><code>Traceback (most recent call last):
    File "&lt;pyshell#6&gt;", line 1, in &lt;module&gt;
      fil = PyPDF2.pdf.PdfFileReader(wFile.read())
    File "C:\Python27\lib\PyPDF2\pdf.py", line 797, in __init__
      self.read(stream)
    File "C:\Python27\lib\PyPDF2\pdf.py", line 1245, in read
      stream.seek(-1, 2)
  AttributeError: 'str' object has no attribute 'seek'
  </code></pre>
  
  <p>Obviously PyPDF2 doesn't like that I'm giving it the <code>urllib.urlopen().read()</code> (which appears to return a string).  I know that this string is not the "text" of the .pdf but a string representation of the file.  How can I resolve this?</p>
  
  <p><strong>EDIT:</strong> NorthCat's solution resolved my error, but when I try to actually extract the text, I get this:</p>
  
  <pre><code>&gt;&gt;&gt; print lFile.getPage(0).extractText()
  ˇˆ˘˘˙˘˘˝˘˛˘ˇ˘ˇ˚ˇˇˇ˘ˆ˘˘˘˚ˇˆ˘ˆ˘ˇ˜ˇ˝˚˘˛˘ˇ ˘˘˘ˇ˛˘˚˚ˆˇˇ!
  ˝˘˚ˇ˘˘˚"˘˘ˇ˘˚ˇ˘˘˚ˇ˘˘˘˙˘˘˘#˘˘˘ˆ˘˛˘˚˛˙ ˘˘˚˚˘˛˙#˘ˇ˘ˇˆ˘˘˛˛˘˘!˘˘˛˘˝˘˘˘˚ ˛˘˘ˇ˘ˇ˛$%&amp;˘ˇ'ˆ˛
  $%&amp;˘ˇˇ˘˚ˆ˚˘˘˘˘ ˘ˆ(ˇˇ˘˘˘˘ˇ˘˚˘˘#˘˘˘ˇ˛!ˇ)˘˘˚˘˘˛ ˚˚˘ˇ˘˝˘˚'˘˘ˇˇ ˘˘ˇ˘˛˙˛˛˘˘˚ˇ˘˘ˆ˘˘ˆ˙
  $˘˘˘*˘˘˘ˇˆ˘˘ˇˆ˛ˇ˘˝˚˚˘˘ˇ˘ˆ˘"˘ˆ˘ˇˇ˘˛ ˛˛˘˛˘˘˘˘˘˘˛˘˘˚˚˘$ˇ˘ˇˆ˙˘˝˘ˇ˘˘˘ˇˇˆˇ˘ ˘˛ˇ˝˘˚˚#˘˛˘˚˘˘ 
  ˘ˇ˘˚˛˛˘ˆ˛ˇˇˇ ˚˘˘˚˘˘ˇ˛˘˙˘˝˘ˇ˘ˆ˘˛˙˘˝˘ˇ˘˘˝˘"˘˛˘˝˘ˇ ˘˘˘˚˛˘˚)˘˘ˆ˛˘˘ 
  ˘˛˘˛˘ˆˇ˚˘˘˘˘˚˘˘˘˘˛˛˚˘˚˝˚ˇ˘#˘˘˚ˆ˘˘˘˝˘˚˘ˆˆˇ˘ˆ 
  ˘˘˘ˆ˘˝˘˘˚"˘˘˚˘˚˘ˇ˘ˆ˘ˆ˘˚ˆ˛˚˛ˆ˚˘˘˘˘˘˘˚˛˚˚ˆ#˘ˇˇˆˇ˘˝˘˘ˇ˚˘ˇˇ˘˛˛˚ ˚˘˘˘ˇ˚˘˘ˇ˘˘˚ˆ˘*˘ 
  ˘˘ˇ˘˚ˇ˘˙˘˚ˇ˘˘˘˙˙˘˘˚˚˘˘˝˘˘˘˛˛˘ˇˇ˚˘˛#˘ˆ˘˘ˇ˘˚˘ˇˇ˘˘ˇˆˇ˘$%&amp;˘ˆ˘˛˘˚˘,
  </code></pre>