How to save multiple file from URLs in one zip using python? -


i scrapping files urls using beautiful soup, , want store files in single zip using python. below code snippet 1 url.

fz = zipfile.zipfile('c:\\users\\admin\\data\\data.zip', 'w')   response = urllib2.urlopen(url/file_name.txt) file = open('c:\\users\\admin\\data\\filename.txt','w') file.write(response.read()) file.close()  fz.write('c:\\users\\admin\\data\\filename.txt',compress_type=zipfile.zip_deflated) fz.close() 

this snippet not working me can 1 please me on this. getting below error:

windowserror: [error 2] system cannot find file specified: 'c:\users\admin\data\filename.txt'

but file present in location.

use:

fz.writestr("file_name", url.read()) 

as many times need. i.e. 1 writestr() per file. select zip's mode (deflated) @ opening of new zip.

so, not need save file disk, pack it. html's name , content , feed them writestr(). zip gets '/' path separator. therefore use like: "/some_dir/some_subdir/index.html" subdirectories or "/index.html" put file root.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -