1

I have the following html structure

  <div id="rn_answertext">
    <p>asdasdasdas</p>
    <p>asdasdasdas</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.

jdeseno
  • 7,753
  • 1
  • 36
  • 34
Amal Kumar S
  • 15,555
  • 19
  • 56
  • 88

2 Answers2

1

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
jdeseno
  • 7,753
  • 1
  • 36
  • 34
1

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.

Community
  • 1
  • 1
suren
  • 969
  • 4
  • 22