gpt4 book ai didi

python - innerhtml 相当于在 lxml.html 中使用 cssselect

转载 作者:行者123 更新时间:2023-11-30 23:38:26 25 4
gpt4 key购买 nike

Possible Duplicate:
Equivalent to InnerHTML when using lxml.html to parse HTML

在 python 2.7 中使用 lxml.html 进行 cssselect 时,innerHTLML 的等效项是什么?

import lxml.html, cssselect

doc = lxml.html.document_fromstring(htmldocstring)
e = doc.cssselect('div.mainl')[0]
print e.innerHTML #This doesn't work

如何获取 e 的内部/外部 html?

外部 html要获取外部 html,请执行以下操作:

print lxml.html.tostring(e)

还是不知道如何获取innerHTML。

最佳答案

明白了...

print lxml.html.tostring(e)

关于python - innerhtml 相当于在 lxml.html 中使用 cssselect,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14511257/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com