title: Python downloading PDF with urllib2 creates corrupt document
body: <p>Last week I defined a function to download pdfs from a journal website. I successfully downloaded several pdfs using:</p>
  
  <pre><code>import urllib2
  def pdfDownload(url):
      response=urllib2.urlopen(url)
      expdf=response.read()
      egpdf=open('ex.pdf','wb')
      egpdf.write(expdf)
      egpdf.close()
  </code></pre>
  
  <p>I tried this function out with:</p>
  
  <pre><code> pdfDownload('http://pss.sagepub.com/content/26/1/3.full.pdf')
  </code></pre>
  
  <p>At the time, this was how the URLs on the journal Psychological Science were formatted. The pdf downloaded just fine. </p>
  
  <p>I then went to write some more code to actually generate the URL lists and name the files appropriately so I could download large numbers of appropriately named pdf documents at once.</p>
  
  <p>When I came back to join my two scripts together (sorry for non-technical language; I'm no expert, have just taught myself the basics) the formatting of URLs on the relevant journal had changed. Following the previous URL takes you to a page with URL '<a href="http://journals.sagepub.com/doi/pdf/10.1177/0956797614553009" rel="nofollow noreferrer">http://journals.sagepub.com/doi/pdf/10.1177/0956797614553009</a>'. And now the pdfDownload function doesn't work anymore (either with the original URL or new URL). It creates a pdf which cannot be opened "because the file is not a supported file type or has been damaged".</p>
  
  <p>I'm confused as to me it seems like all has changed is the formatting of the URLs, but actually something else must have changed to result in this? Any help would be hugely appreciated.</p>