Sunday 15 August 2010

python - File download via Post form -


is a website that has a list of files that I want to download. To reduce the process, I tried to write a script to do this for myself. (Although I can choose multiple options at the same time, only by clicking on submitting the first file)

The webpage URL is different from the action in the webpage / list.FPP form. I'm not sure what the policy is posting the actual url.

  & lt; Form action = "webpage / data.php" method = "post" & gt; & Lt; Table align = "center" & gt; & Lt; Tbody & gt; & Lt; TR & gt; & Lt; TD & gt; & Lt; Select name = "data []" size = "8" multi = "multiple" & gt; & Lt; Option value = "downloadable_file 1.tar" & gt; Downloadable file 1 & lt; / Options & gt; & Lt; Option value = "downloadable_file2.tar" & gt; Downloadable file 2 & lt; / Option & gt; & Lt; Option value = "downloadable_file 3.tar" & gt; Downloadable file 3 & lt; / Options & gt; & Lt; / Select & gt; & Lt; / TD & gt; & Lt; / TR & gt; & Lt; / Tbody & gt; & Lt; / Table & gt; & Lt; Input type = "submit" & gt; & Lt; / Form & gt;   

I have a script:

  import urlib import urllib2 import modesty rake = urllib2.Request ( 'webpage / list.php') value = { ' data [] ':' downloadable_file1.tar '} req.add_data (urllib.urlencode (value)) resp = urllib2.urlopen (req) myfile = open (' downloadable_file1.tar ',' wb ') shutil.copyfileobj (Resp. Fp, myfile) myfile.close ()   

While running the script, the server does not seem to accept the request and only gives me the service of the same webpage with the file list. Do not I have any choice? Maybe there is a problem redirect?

This information is what I get when using Chrome:

  URL of the request: webpage / data. Php request meth: post status code: accept 200 OK: Text / html, application / xhtml + xml, application / xml; Q = 0.9, * / *; Q = 0.8 Acceptable-charset: ISO-8859-1, UTF-8; Q = 0.7, *; Q = 0.3 encoding-encoding: accept jeep, bend, SDC-language: SV-SE, SV; Q = 0.8, N-US; Q = 0.6, N; Q = 0.4 Cache-Control: max-age = 0 Connection: keep-alive Content-Length: 26 Content-type: application / x-www-form-urlencoded host: website Origin: webpage manual webpage / list.php User agent: Mozilla / 5.0 (Macintosh; Intel Mac OS X L0_6_8) Apple Vebkat / 537.22 (KHTML, like Gecko) Chrome / 25.0.1364.172 Safari / 537.22 data []: downloadable_file1.tar acceptable limits: bytes cache-control: private connections : Keep-alive Content-Settings: Attachments; Filename = "download Yogy_fail 1.tar.gz" Content-Length: 1043436 Content-Transfer-Encoding: binary Content-Type: application / x-Jijip Date: Tue Mar 26 2013 20:18:58 GMT End: Mon, Keep 26 Julai 1997 05:00:00 GMT-Elivः timeout = 5, max = 100 Pragः Private server: Apache / 2.2.9 (FreeBSD) mod_ssl / 2.2.9 OpenSSL / 0.9.7 e-P1 DAV / 2 PHP / 5.2 .6 Suhosin Patch with X-Power: PHP / 5.2.6    

Should 'Request' Library Consider using the following:

I believe this request will be complete with the use of the library:

  data = {'data []': ' File.write (req.content) as the downloadable_file1 file as' file.data ',' wb ') .tar'} req = requests.post ('webpage / data.php', data):    

No comments:

Post a Comment