Created
October 21, 2010 23:11
-
-
Save paul/639569 to your computer and use it in GitHub Desktop.
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' | |
doc = <<-DOC | |
<dl> | |
<dt>Label</dd> | |
<dd class=other>Other Value</dd> | |
<dt>Label</dt> | |
<dd class=foo>Value</dd> | |
<dd class=foo>Trying to select this dd</dd> | |
<dd class=other>Other Value</dd> | |
</dl> | |
DOC | |
n = Nokogiri::HTML(doc) | |
[ | |
"dd.foo", | |
"dd:last", | |
"dd.foo:last", | |
"dd.foo:last-of-type", | |
"dd.foo:nth-of-type(3)", | |
"dd[class=foo]:last", | |
].each do |selector| | |
puts "Selector: #{selector}" | |
puts n.css(selector) | |
puts "\n" | |
end | |
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
Selector: dd.criterion | |
<dd class="criterion">Value</dd> | |
<dd class="criterion">Trying to select this dd</dd> | |
Selector: dd:last | |
<dd class="other">Other Value</dd> | |
Selector: dd.criterion:last | |
Selector: dd.criterion:last-of-type | |
Selector: dd.criterion:nth-of-type(3) | |
<dd class="criterion">Trying to select this dd</dd> | |
Selector: dd[class=criterion]:last |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment