1
比方说,我有这样的例子:引入nokogiri如何获取父文本,而不是孩子的文本和参考文本回其父
page = "<html><body><h1 class='foo'></h1><p class='foo'>hello people<a href='http://'>hello world</a></p></body></html>"
@nodes = []
Nokogiri::HTML(page).traverse do |n|
if n[:class] == "foo"
@nodes << {:name => n.name, :xpath => n.path, :text => n.text }
end
end
结果将在n.text
将hello peoplehello world
,我想做到这一点的方式,所以我可以得到父文本及其孩子的文字,但其中涉及到他们的标签
所以结果会是这样的
@nodes[0][:text]=""
@node[1][:text]= [{:Elementtext1 => "hello people", :ElementObject1 => elementObject},{:Elementtext2 => "hello world", :ElementObject2 => elementObject}]
非常感谢adrian – Waheedi 2009-12-08 11:07:10