title: Download .pdf files from a webiste using python
body: <p>i am trying to download all the pdfs from the webiste provided and i am using the following code:</p>
  
  <pre><code>import mechanize
  from time import sleep
  br = mechanize.Browser()
  
  
  br.open('http://www.nerc.com/comm/CCC/Pages/AgendasHighlightsandMinutes-.aspx')
  
  f=open("source.html","w")
  f.write(br.response().read()) 
  
  filetypes=[".pdf"] 
  myfiles=[]
  for l in br.links(): 
      for t in filetypes:
          if t in str(l): 
              myfiles.append(l)
  
  
  def downloadlink(l):
      f=open(l.text,"w") 
      br.click_link(l)
      f.write(br.response().read())
      print l.text," has been downloaded"
  
  
  for l in myfiles:
      sleep(1) 
      downloadlink(l)
  </code></pre>
  
  <p>keep on getting the following error and can't figure out the problem why.</p>
  
  <pre><code>legal and privacy  has been downloaded
  Traceback (most recent call last):
    File "downloads-pdfs.py", line 29, in &lt;module&gt;
      downloadlink(l)
    File "downloads-pdfs.py", line 21, in downloadlink
      f=open(l.text,"w")
  IOError: [Errno 13] Permission denied: u'/trademark policy'
  </code></pre>