Nokogiri is a pretty simple and straightforward gem. In the coming few pages we will take a more in-depth look at the most important methods, along with a few useful Ruby methods to take your parsing skills to the next level.
css(rules) —> NodeSet
css method searches self for nodes matching CSS rules and returns an iterable NodeSet. Self is a
Nokogiri::HTML::Document. In contrast to the
at_css method used in the quick start project, the
css method returns all nodes that match the CSS rules. The
at_css method only returns the first node.
The following is a
css method example:
# import nokogiri to parse and open-uri to scrape require 'nokogiri' require 'open-uri' # create a new Nokogiri HTML document ...