Nokogiri returning values as a string, not an array

前端 未结 2 1151
逝去的感伤
逝去的感伤 2021-01-20 16:05

I\'m running a script using Nokogiri that returns multiple values. I was under the impression (and reassured by multiple sources) that the results should be in the form of a

2条回答
  •  伪装坚强ぢ
    2021-01-20 16:55

    NodeSet#text always returns a string (otherwise it would probably be called NodeSet#texts). Nokogiri docs are not so great, when in doubt check the source code:

      # lib/nokogiri/xml/node_set.rb
      def inner_text
        collect{|j| j.inner_text}.join('')
      end
      alias :text :inner_text
    

    To get an array of texts: nodes.map(&:text)

提交回复
热议问题