Created
October 21, 2010 23:21
-
-
Save paul/639595 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
Selector: dd.foo | |
<dd class="foo">Value</dd> | |
<dd class="foo">Trying to select this dd</dd> | |
Selector: dd:last | |
<dd class="other">Other Value</dd> | |
Selector: dd.foo:last-child | |
Selector: dd.foo:last-of-type | |
Selector: dd.foo:nth-of-type(3) | |
<dd class="foo">Trying to select this dd</dd> | |
Selector: dd.foo:nth-last-of-type(1) | |
<dd class="foo">Trying to select this dd</dd> |
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-child", | |
"dd.foo:last-of-type", | |
"dd.foo:nth-of-type(3)", | |
"dd.foo:nth-last-of-type(1)", | |
].each do |selector| | |
puts "Selector: #{selector}" | |
puts n.css(selector) | |
puts "\n" | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment