BeautifulSoup的innerHTML? [英] BeautifulSoup innerhtml?
问题描述
比方说,我有一个 DIV
的页面。我可以轻松地获得与 soup.find该div()
。
Let's say I have a page with a div
. I can easily get that div with soup.find()
.
现在,我有结果,我想打印整个的innerHTML
的是 DIV
:我意思是说,我需要所有的HTML标签和文本的所有toegether一个字符串,酷似字符串我可以在javascript与 obj.innerHTML
。这可能吗?
Now that I have the result, I'd like to print the WHOLE innerhtml
of that div
: I mean, I'd need a string with ALL the html tags and text all toegether, exactly like the string I'd get in javascript with obj.innerHTML
. Is this possible?
推荐答案
有一个未公开的函数,它近似 DOM的innerHTML的方法:
There is an undocumented function that does approximate the DOMs innerHTML method:
def innerHTML(element):
return element.decode_contents(formatter="html")
本已通过了所有我的测试案例至今。也许有人要更新文档?
This has passed all my test cases so far. Perhaps someone should update the docs?
这篇关于BeautifulSoup的innerHTML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!