HTML parser example, anybody?

haering at informatik.tu-muenchen.de haering at informatik.tu-muenchen.de
Thu Apr 27 20:38:26 EDT 2000


In comp.lang.python, you wrote:
>Why don't you just use Python's string syntax, e.g. if you have the
>following in a template file called foo.templ:
>
>   <html><head><title>%(title)s</title></head>
>   <body><h1>%(heading)s</h1></body></html>
>
>you can do something like:
>
>   htmlfile = open('foo.html', 'w')
>   replacements = {
>     'title':   'my title',
>     'heading': 'A Heading',
>   }
>   htmlfile.write( open(foo.templ).read() % replacements )
>   htmlfile.close()
>
>-- bjorn
>

Thanks for the info, but I'd rather transform HTML -> HTML. My current
project uses special comments of the form <!-- at INS keyword param1=value1
param2=value2 -->. I'd like to parse for comments and filter out + process these. The
prime reason for a real parser is that I need to rewrite all links in the
HTML source tree and do some other checks.

Gerhard




More information about the Python-list mailing list