こんにちは私はnokogiriに不慣れで、さまざまなツリー構造を持つHTMLドキュメントを解析しようとしています。それを解析する方法についての提案は素晴らしいでしょう。このページのすべてのテキストをキャプチャしたいと思います。
<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>
私はこれを試しましたが、それはそれぞれの完全な配列を出力するだけであり、「スタッフ」の部分に到達する方法さえわかりません。
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
ヘルプをいただければ幸いです。