Instead of saving text files i need as html

Tim Chase tim at thechases.com
Thu Jun 8 12:39:55 EDT 2006


> Is this what you mean?
> 
> -----begin-----
> import urllib
> urlfile = open(r'c:\temp\url.txt', 'r')
> for lines in urlfile:
>     try:
>         outfilename = lines.replace('/', '-')
>         urllib.urlretrieve(lines.strip('/n'), 'c:\\temp\\' \
>         + outfilename.strip('\n')[7:] + '.html')
>     except:
>         pass
> -----end-----

[laughs]  I suspect the urlretrieve line should contain 
"strip('\n')" instead of "strip('/n')", but otherwise, the 
original code looked pretty kosher.  I'm not sure what the odd 
slicing is for, but I'll presume the OP knows what they're doing.

While not a python solution, the standard *nix tool would be 
either wget or curl:

	bash> wget -i listofurls.txt

which is freely available with the Cygwin suite of GNU tools for 
Win32 platforms.

-tkc






More information about the Python-list mailing list