Hello,
In an HTML page ("target"), I'd like to replace the body's text with the body from another file ("source").
Neither ".string", ".text", nor "str()" seems the right way to do it :-/ Does someone know?
Thank you.
In an HTML page ("target"), I'd like to replace the body's text with the body from another file ("source").
Neither ".string", ".text", nor "str()" seems the right way to do it :-/ Does someone know?
Thank you.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
""" target <body> <div id="body">FILL_ME</div> </body> """ #TypeError: decoding to str: need a bytes-like object, NoneType found target.body.find( 'div' , id = 'body' ).string = source.body.string #< target.body.find( 'div' , id = 'body' ).string = str (source.body) #plain text, tags gone target.body.find( id = "body" ).string.replace_with(source.body.text) #TypeError: decoding to str: need a bytes-like object, Tag found target.body.find( 'div' , id = 'body' ).string = source.body #AttributeError: 'NoneType' object has no attribute 'replace_with' target.body.find(string = "FILL_ME" ).replace_with(source.body) |