Created
May 30, 2015 08:17
-
-
Save streetcarmonkey/967b50b50cb59a26a212 to your computer and use it in GitHub Desktop.
Ruby Nokogiri: Get class attribute of a TR element (or any other node for that matter)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'nokogiri' | |
html = %q{ | |
<table> | |
<tr class="even_class"> | |
<td></td> | |
</tr> | |
<tr class="odd_class"> | |
<td></td> | |
</tr> | |
</table> | |
} | |
doc = Nokogiri::HTML(html) | |
rows = doc.xpath("//tr") | |
rows.each do | row | | |
puts row.attr('class') | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment