开发者

How to get raw XML back from lxml?

开发者 https://www.devze.com 2023-01-21 11:59 出处:网络
I\'m using the following code to locate a div: parser = etree.HTMLParser() tree = etree.parse(StringIO(page), parser)

I'm using the following code to locate a div:

parser = etree.HTMLParser()
tree = etree.parse(StringIO(page), parser)

div = tree.xpath("//div[@class='content']")[0]

My only problem is, that after doing this I do not want to rely on lxml to extract the contents of said div: I just want to get back th开发者_开发知识库e raw XML the div contains. Is this doable or do I have to abandon this method entirely?


I think you are looking for:

etree.tostring(div)


Did you try tostring?

raw_xml = etree.tostring(div)
0

精彩评论

暂无评论...
验证码 换一张
取 消