Is this your html, or are you scraping someone else's html?
If it's yours, organize your html differently... if you know you want to
be processing a section at a time, wrap those sections with an
identifiable container, then scope your searches by the container.
<div>
<h3>blah</h3>
<li>a</li>
<li>b</li>
</div>
<div>
<h3>blah2</h3>
<li>c</li>
<li>d</li>
</div>
(doc/"div").each do |dv|
this_h3 = (dv/"h3")
if this_h3.inner_html == "blah2"
(dv/"li").each do |li|
puts li.inner_html
end
end
end
emits just c, and d
If its someone else's html in that format, you'll probably have to go
elem by elem for the whole doc with state machine-ish code to track what
you've seen previously since there doesn't seem to be any real 'path' to
the li's per h3.
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---