Hi I'm new to nokogiri and trying to parse an HTML document with a varied tree structure. Any suggestions on how to go about parsing it would be great. I'd like to capture all the text on this page.
<div class = "main"> Title</div>
<div class = "subTopic">
<span = "highlight">Sub Topic</span>Stuff
</div>
<div class = "main"> Another Title</div>
<div class = "subTopic">
<span class = "highlight">Sub Topic Title I</span>Stuff<br>
<span class = "highlight">Sub Topic Title II</span>Stuff<br>
<span class = "highlight">Sub Topic Title III</span>Stuff<br>
</div>
I tried this but it just puts out each full array and I'm not even sure how to get to the "Stuff" part.
content = Nokogiri::HTML(open(@url))
content.css('div.main').each do |m|
puts m .text
content.css('div.subTopic').each do |s|
puts s.text
content.css('span.highlight').each do |h|
puts h.text
end
end
end
Help will be appreciated.