ParseError: not well-formed (invalid token) using cElementTree

前端 未结 13 1040
日久生厌
日久生厌 2020-12-16 11:10

I receive xml strings from an external source that can contains unsanitized user contributed content.

The following xml string gave a ParseError in cElementTre

13条回答
  •  天涯浪人
    2020-12-16 11:27

    It seems to complain about \x08 you will need to escape that.

    Edit:

    Or you can have the parser ignore the errors using recover

    from lxml import etree
    parser = etree.XMLParser(recover=True)
    etree.fromstring(xmlstring, parser=parser)
    

提交回复
热议问题