title: How to download files from a web based file server with Python Mechanize
body: <p>I have a series of files on a private ftp file server that I am trying to download using mechanize. </p>
  
  <p>The mechanize link objects have the structure</p>
  
  <pre><code>Link(base_url='http://myfileserver.com/cgi-bin/index.cgi', url='index.cgi?page=download&amp;file=%2Fhome%2Fjmyfileserver%2Fpublic_html%2Fuser_data%2Fmycompany%2F.ftpquota', text='Download [IMG]', tag='a', attrs=[('href', 'index.cgi?page=download&amp;file=%2Fhome%2Fjmyfileserver%2Fpublic_html%2Fuser_data%2Fmycompany%2F.ftpquota'), ('class', 'ar')])
  </code></pre>
  
  <p>This basically corresponds to a link where a file icon is linked to the file </p>
  
  <p></p>
  
  <p>I am new to mechanize.<br>
  But how do I download the linked file  can be got from </p>
  
  <pre><code>urlparse.urljoin(base_url , url)
  </code></pre>
  
  <p>Which combines the two to get : </p>
  
  <pre><code>http://myfileserver.com/cgi-bin/index.cgi?page=download&amp;file=%2Fhome%2Fjmyfileserver%2Fpublic_html%2Fuser_data%2Fmycompany%2F.ftpquota
  </code></pre>
  
  <p>I dont know how to proceed.</p>
  
  <p>My raw code</p>
  
  <pre><code>import mechanize
  import subprocess
  import urlparse
  br = mechanize.Browser()
  br.open("http://myfileserver.com/cgi-bin/index.cgi")
  br.select_form(nr=0)
  br['login'] = "mylogin"
  br['password'] = "mypassword"
  br.submit()
  #print dir(br)
  myfiles = []
  for alink in br.links():
      print alink
      myfiles.append(alink)
  
  def downloadlink(l):
      print " Trying to download", l.url.split("%2F")[-1]
      f=open(l.url.split("%2F")[-1],"w") 
      myurl = urlparse.urljoin(l.base_url,l.url)
      print myurl
      # Dont know how to proceed
  
  
  
  for linkobj in myfiles:
  
      if "sca" in linkobj.url:
          #br.follow_link(text='[IMG]', nr=0)
          downloadlink(linkobj)
  </code></pre>