How do I get innerHtml using Nokogiri gem

安稳与你 提交于 2019-12-01 15:43:18

问题


e.g. i have html:

<div class="item">
    <p>
        bla bla<br/>
        bla bla
    </p>
</div>

i need to get inner html of div.item:

 <p>
    bla bla<br/>
    bla bla
 </p>

i know that i can use:

doc.css("div.item:first").text

text method return clean text without any html tags

but what should i do for getting inner html of div.item?

tried:

doc.css("div.item:first").html

but doesn't work, documentation did not help as well

any ideas?


回答1:


If you just need the string:

doc.css("div.item:first").inner_html


来源:https://stackoverflow.com/questions/7697662/how-do-i-get-innerhtml-using-nokogiri-gem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!