in Education by
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)

1 Answer

0 votes
by
You could try with: for index, linkobj in enumerate(myfiles): if "sca" in linkobj.url: resp = br.follow_link(text='Download [IMG]',nr=0) content = resp.read() with open('output%s.txt' % index, 'w') as fo: fo.write(content)

Related questions

0 votes
    I am working on Automation Anywhere RPA platform to automate below process - 1. Login to a website using Username ... and Password). Select the correct answer from above options...
asked Feb 1, 2022 in Education by JackTerrance
0 votes
    At first I made an application that downloads a file from the entered link and displays information about ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 19, 2022 in Education by JackTerrance
0 votes
    I am new at using Ansible. I tried to create directories and download files using Ansible. Should I use shell ... module is available? Select the correct answer from above options...
asked Jan 22, 2022 in Education by JackTerrance
0 votes
    All How can I download a file so the user sees that it is downloading (like with a stream?) I ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 2, 2022 in Education by JackTerrance
0 votes
    After working with .NET's HttpWebRequest/Response objects, I'd rather shoot myself than use this to crawl ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 21, 2022 in Education by JackTerrance
0 votes
    I would like to use API Gateway to pass through binary payloads from a local Express.js server that sends ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 22, 2022 in Education by JackTerrance
0 votes
    I want to change a couple of files at one time, iff I can write to all of them. I'm wondering if I ... to this problem look like? Select the correct answer from above options...
asked Jan 30, 2022 in Education by JackTerrance
0 votes
    You can download base R system from _________ (a) A (b) B (c) CRAN (d) D This question was ... Getting Started of R Programming Select the correct answer from above options...
asked Feb 15, 2022 in Education by JackTerrance
0 votes
    Download copy, extract data from an open system done fraudulently is treated as _________ (a) cyber-warfare (b) ... Security questions and answers pdf, mcq on Cyber Security pdf,...
asked Nov 4, 2021 in Education by JackTerrance
0 votes
    Can someone tell me how to find all the files in directory with .txt extension in Python? Select the correct answer from above options...
asked Jan 23, 2022 in Education by JackTerrance
0 votes
    I have an XML file which is structured as follows: place1 location1 place2 location2 place3 location3 These ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 2, 2022 in Education by JackTerrance
0 votes
    I have a file that looks like this: NODE=SC-1,CPU=90 NODE=SC-1,MEM=10 NODE=SC-1,FS=80 ... questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    I have a file that looks like this: NODE=SC-1,CPU=90 NODE=SC-1,MEM=10 NODE=SC-1,FS=80 ... questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    I'm a registered developer in apple. I have installed OSX Lion and i want to install XCode but i ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 26, 2022 in Education by JackTerrance
...