I have a series of files on a private ftp file server that I am trying to download using mechanize.
The mechanize link objects have the structure
Link(base_url='
http://myfileserver.com/cgi-bin/index.cgi', url='index.cgi?page=download&file=%2Fhome%2Fjmyfileserver%2Fpublic_html%2Fuser_data%2Fmycompany%2F.ftpquota', text='Download [IMG]', tag='a', attrs=[('href', 'index.cgi?page=download&file=%2Fhome%2Fjmyfileserver%2Fpublic_html%2Fuser_data%2Fmycompany%2F.ftpquota'), ('class', 'ar')])
This basically corresponds to a link where a file icon is linked to the file
I am new to mechanize.
But how do I download the linked file can be got from
urlparse.urljoin(base_url , url)
Which combines the two to get :
http://myfileserver.com/cgi-bin/index.cgi?page=download&file=%2Fhome%2Fjmyfileserver%2Fpublic_html%2Fuser_data%2Fmycompany%2F.ftpquota
I dont know how to proceed.
My raw 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)
JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)