开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜