I’m trying to download a zip file (“tl_2008_01001_edges.zip”) from an ftp census site using urllib. What form is the zip file in when I get it and how do I save it?
I’m fairly new to Python and don’t understand how urllib works.
This is my attempt:
import urllib, sys
zip_file = urllib.urlretrieve("ftp://ftp2.census.gov/geo/tiger/TIGER2008/01_ALABAMA/Autauga_County/", "tl_2008_01001_edges.zip")
If I know the list of ftp folders (or counties in this case), can I run through the ftp site list using the glob function?
Thanks.
Use
urllib2.urlopen()for the zip file data and directory listing.To process zip files with the
zipfilemodule, you can write them to a disk file which is then passed to thezipfile.ZipFileconstructor.Retrieving the data is straightforward using
read()on the file-like object returnedby
urllib2.urlopen().Fetching directories:
Or, splitting for directory names: