How can i find <li class="data-brand"> using nokogiri ?

How can i find

  • using nokogiri after running Nokogiri::HTML::Parse
  • Two options, both using the CSS syntax:

    @doc = Nokogiri::HTML.parse(...)

    1. Get all of the elements that match that selector:

    @doc.css('li.data-brand').each do |elm|
      # do whatever with elm here
    end

    2. Get the first one in document source order:

    elm = @doc.at_css('li.data-brand')

    Walter