Nokogiri: need to turn markup partitioned by `hr` into divs
问题 Given markup inside an HTML document that looks like this <h3>test</h3> <p>test</p> <hr/> <h3>test2</h3> <p>test2</p> <hr/> I'd like to to produce this <div> <h3>test</h3> <p>test</p> </div> <div> <h3>test2</h3> <p>test2</p> </div> What's the most elegant way to do with with Nokogiri? 回答1: Edit : Reworked answer to be a bit cleaner. Edit2 : Small rewrite to shorten by two lines require 'nokogiri' doc = Nokogiri::HTML <<ENDHTML <h3>test</h3> <p>test</p> <hr/> <h3>test2</h3> <p>test2</p> <hr/>