replacing words in HTML file

Daniel Fetchinson fetchinson at googlemail.com
Wed Apr 28 16:03:02 EDT 2010


> Any idea how I can replace words in a html file? Meaning only the
> content will get replace while the html tags, javascript, & css are
> remain untouch.

I'm not sure what you tried and what you haven't but as a first trial
you might want to

<untested>

f = open( 'new.html', 'w' )
f.write( open( 'index.html' ).read( ).replace( 'replace-this', 'with-that' ) )
f.close( )

</untested>

HTH,
Daniel




-- 
Psss, psss, put it down! - http://www.cafepress.com/putitdown



More information about the Python-list mailing list