The input is a full document, so this call should be Nokogiri::HTML::Document.parse(doc) or simply Nokogiri::HTML(doc)