Skip to content

Instantly share code, notes, and snippets.

@JosephPecoraro
Created April 23, 2009 23:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JosephPecoraro/100848 to your computer and use it in GitHub Desktop.
Save JosephPecoraro/100848 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'hpricot' # hpricot-0.6.164
html = <<END
<html><head></head><body><table>
<tr><td>R0C0</td><td>R0C1</td><td>R0C2</td><td>R0C3</td></tr>
<tr><td>R1C0</td><td>R1C1</td><td>R1C2</td><td>R1C3</td></tr>
<tr><td>R2C0</td><td>R2C1</td><td>R2C2</td><td>R2C3</td></tr>
</table></body></html>
END
puts html
doc = Hpricot(html)
yours = (doc/"html/body/table/tr").map {|row| (row/"td").map {|ele| ele.inner_text}}
mine = (doc/"html/body/table/tr").map do |row|
(row/"td").map do |cell|
cell.inner_text
end
end
p yours
p mine
p yours == mine
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment