insert html into ElementTree without parsing it

G

graeme.pietersz

I am building HTML pages using ElementTree.

I need to insert chunks of untrusted HTML into the page. I do not need or want to parse this, just insert it at a particular point as is.

The best solutions I can think of are rather ugly ones: manipulating the string created by tostring.

Is there a nicer way of doing this? Is it possible, for example, to customise how an element is converted to a string representation? I am open to using something else (e.g. lxml) if necessary.
 
S

Stefan Behnel

(e-mail address removed), 24.02.2014 10:45:
I am building HTML pages using ElementTree.
I need to insert chunks of untrusted HTML into the page. I do not need or want to parse this, just insert it at a particular point as is.

How would you want to find out if it can be safely inserted or not without
parsing it?

The best solutions I can think of are rather ugly ones: manipulating the string created by tostring.

Is there a nicer way of doing this? Is it possible, for example, to customise how an element is converted to a string representation? I am open to using something else (e.g. lxml) if necessary.

lxml has a tool to discard potentially unsafe content from HTML files:

http://lxml.de/lxmlhtml.html#cleaning-up-html

Stefan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top