Instead of saving text files i need as html

3c273 nospam at nospam.com
Thu Jun 8 12:45:57 EDT 2006


"Shani" <Shani718 at gmail.com> wrote in message
news:1149777499.506986.292830 at j55g2000cwa.googlegroups.com...
> I have the following code which takes a list of urls
> "http://google.com", without the quotes ofcourse, and then saves there
> source code as a text file. I wan to alter the code so that for the
> list of URLs an html file is saved.
>
> -----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:] + '.txt')
>     except:
>         pass
> -----end-----
>
Or is this what you mean?
-----begin-----
import urllib
urlfile = open('c:\\temp\\url.txt', 'r')
newurlfile = open('c:\\temp\\newurls.html', 'w')
newurlfile.write('<html> \n<body>\n')
for lines in urlfile:
    try:
        if lines == '\n':
            pass
        else:
            lines = '<a href="' + lines.strip() +'">'\
             + lines.strip() + '</a>' + '<br>\n'
            newurlfile.write(lines)
    except:
        pass
newurlfile.write('</body> \n</html>')
urlfile.close()
newurlfile.close()
-----end-----
Louis





More information about the Python-list mailing list