How to remove a particular content inside a div using Hpricot
I have the following html structure
<div id="rn_answertext">
<p>asdasdasdas</p>
<p>asdasdas开发者_StackOverflowdas</p>
<p>asdasdasdas</p>
<h3>asdasdasdas</h3>
<div id="test">Content to be excluded</div>
</div>
What I need is, when I search for div id="rn_answertext" I need to get all the contents except that in the div with id=test
My current code is
result = doc.search("div#rn_answertext").inner_html
Anyone please help.
First get the div you want, then find the div inside you'd like to remove:
div = (doc/"div#rn_answertext")
(div/"#test").remove
puts div.to_s
div = doc.search("//div[@id='rn_answertext']")
div.search('//div[@id="test"]').remove.html
Will give you the rn_answertext div content except test div.
精彩评论