module Nokogiri::XML::Searchable
def css(*args)
you'll never find anything. However, "H1" might be found in an XML document, where tags
tags will match only lowercase CSS queries, so if you search for "H1" in an HTML document,
⚠ NOTE that the CSS query string is case-sensitive with regards to your document type. HTML
node.css('li[2]') # retrieve the second li element in a list
# equivalent to 'li:nth-child(2)'
example:
⚠ NOTE that indices are 1-based like +:nth-child+ and not 0-based like Ruby Arrays. For
💡 Array-like syntax is supported in CSS queries as an alternative to using +:nth-child()+.
node.css
node.css('div @class')
# ⚠ this returns +class+ attributes from all +div+ elements AND THEIR CHILDREN!
node.css('img / @href') # same
node.css('img > @href') # returns all +href+ attributes on an +img+ element
💡 Some XPath syntax is supported in CSS queries. For example, to query for an attribute:
node.css('title:regex("\w+")', handler)
}.new
end
node_set.find_all { |node| node['some_attribute'] =~ /#{regex}/ }
def regex(node_set, regex)
handler = Class.new {
NodeSet. Any other arguments are ones that you pass in. For example:
class you want defined. The first argument to the method will be the matching context
function. To define custom pseudo classes, create a class and implement the custom pseudo
💡 Custom CSS pseudo classes may also be defined which are mapped to a custom XPath
node.css('bike|tire', {'bike' => 'http://schwinn.com/'})
A hash of namespace bindings may be appended. For example:
node.css('div + p.green', 'div#one')
node.css('body h1.bold')
node.css('title')
selectors. For example:
Search this object for CSS +rules+. +rules+ must be one or more CSS
css(*rules, [namespace-bindings, custom-pseudo-class])
call-seq:
##
def css(*args) rules, handler, ns, _ = extract_params(args) css_internal(self, rules, handler, ns) end