Let's say I have this sample:
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
the results would for the n.text
would be hello peoplehello world
, I want to do it in a way so I can get the parent text and its childs text, but relate them to their tag
so the result would be something like
@nodes[0][:text]=""
@node[1][:text]= [{:Elementtext1 => "hello people", :ElementObject1 => elementObject},{:Elementtext2 => "hello world", :ElementObject2 => elementObject}]