Skip to content

Commit

Permalink
Merge pull request #28 from udhayprakash/pixeebot/drip-2024-02-27-pix…
Browse files Browse the repository at this point in the history
…ee-python/safe-lxml-parsing

Use Safe Parsers in `lxml` Parsing Functions
  • Loading branch information
udhayprakash committed Mar 4, 2024
2 parents bfc8cfc + 52a66b8 commit 7347722
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from io import StringIO

from lxml import etree
import lxml.etree

# Feeding RAW XML for Serialisation
html = etree.XML(
Expand All @@ -21,13 +22,13 @@

# The parse() function can be used to parse from files and file-like objects
title = StringIO("<title>Title Here</title>")
tree = etree.parse(title)
tree = etree.parse(title, parser=lxml.etree.XMLParser(resolve_entities=False))
print(etree.tostring(tree).decode("utf-8"))


# The fromstring() function can be used to parse Strings:
title = "<title>Title Here</title>"
root = etree.fromstring(title)
root = etree.fromstring(title, parser=lxml.etree.XMLParser(resolve_entities=False))
print(root.tag)
print(etree.tostring(root).decode("utf-8"))

Expand Down

0 comments on commit 7347722

Please sign in to comment.