更新时间:2023-12-05 09:26:28
你想要只文本?
doc.search('//text()').map(&:text)
也许你不想要所有的空白和噪音.如果只想要包含单词字符的文本节点,
Maybe you don't want all the whitespace and noise. If you want only the text nodes containing a word character,
doc.search('//text()').map(&:text).delete_if{|x| x !~ /\w/}
看来您只想要单个节点的文本内容:
It appears you only wanted the text content of a single node:
some_node.at_xpath( "//whatever" ).text