I'm not sure about the point of using an array of hashes, and without an example I can't suggest something. However, for splitting the text on <br>
tags, I'd go about it this way:
require 'nokogiri'
doc = Nokogiri::HTML('<td class="j">
<a title="title text1" href="http://link1.com">Link 1</a> (info1), Blah 1,<br>
<a title="title text2" href="http://link2.com">Link 2</a> (info1), Blah 1,<br>
<a title="title text2" href="http://link3.com">Link 3</a> (info2), Blah 1 Foo 2,<br>
</td>')
doc.search('br').each do |n|
n.replace("
")
end
doc.at('tr.j').text.split("
") # => ["", " Link 1 (info1), Blah 1,", "Link 2 (info1), Blah 1,", "Link 3 (info2), Blah 1 Foo 2,"]
This will get you closer to a hash:
Hash[*doc.at('td.j').text.split("
")[1 .. -1].map{ |t| t.strip.split(',')[0 .. 1] }.flatten] # => {"Link 1 (info1)"=>" Blah 1", "Link 2 (info1)"=>" Blah 1", "Link 3 (info2)"=>" Blah 1 Foo 2"}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…