Skip to content Skip to sidebar Skip to footer

Html Code Processing

I want to process some HTML code and remove the tags as in the example: '

This is a very interesting paragraph.

' results in 'This is a very int

Solution 1:

This question may help you: Strip HTML from strings in Python

No matter what solution you choose, I'd recommend avoiding regular expressions. They can be slow when processing large strings, they might not work due to invalid HTML, and stripping HTML with regex isn't always secure or reliable.

Solution 2:

Solution 3:

import libxml2

text = "<p><b>This</b> is a very interesting paragraph.</p>"
root = libxml2.parseDoc(text)
print root.content

# 'This is a very interesting paragraph.'

Solution 4:

Depending on your needs, you could just use the regular expression /<(.|\n)*?>/ and replace all matches with empty strings. This works perfectly for manual cases, but if you're building this as an application feature then you'll need a more robust and secure option.

Solution 5:

you can use lxml.

Post a Comment for "Html Code Processing"