如何使用Nokogiri gem获得innerHtml [英] How do I get innerHtml using Nokogiri gem
本文介绍了如何使用Nokogiri gem获得innerHtml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
例如我有html:
<div class="item">
<p>
bla bla<br/>
bla bla
</p>
</div>
我需要获取div.item的内部html:
i need to get inner html of div.item:
<p>
bla bla<br/>
bla bla
</p>
我知道我可以使用:
doc.css("div.item:first").text
文本方法返回无任何html标记的纯文本
text method return clean text without any html tags
但是我应该如何获取div.item的内部html?
but what should i do for getting inner html of div.item?
尝试:
doc.css("div.item:first").html
但不起作用,文档也没有帮助
but doesn't work, documentation did not help as well
有什么想法吗?
推荐答案
如果只需要字符串:
doc.css("div.item:first").inner_html
这篇关于如何使用Nokogiri gem获得innerHtml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文