code debugging
Gabriel Genellina
gagsl-py2 at yahoo.com.ar
Sun Jul 26 05:19:52 EDT 2009
En Sun, 26 Jul 2009 03:33:27 -0300, golu <bhardwajjayesh7 at gmail.com>
escribió:
> i want to save pages in a directory and i m using the urls to get
> filenames. The program gets stuck in the saving step.can u suggest me
> a way to save a page e.g google.com as a file google.html
You may use str.translate to replace/remove all undesired characters:
py> import string
py> valid = string.ascii_letters+string.digits+'.'
py> invalid = ''.join(chr(x) for x in range(256) if chr(x) not in valid)
py> table = string.maketrans(invalid, '_'*len(invalid))
py> x = 'http://docs.python.org/library/string.html'
py> x.translate(table)
'http___docs.python.org_library_string.html'
See http://docs.python.org/library/stdtypes.html#str.translate
--
Gabriel Genellina
More information about the Python-list
mailing list