Created
November 10, 2009 18:51
-
-
Save res0nat0r/231155 to your computer and use it in GitHub Desktop.
Breadcrumbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
require 'rubygems' | |
require 'nokogiri' | |
text="<html><body><div class='body'><p class='main'>some text here</p></div></body></html>" | |
doc = Nokogiri::HTML(text) | |
root = doc.root | |
node = doc.xpath('//p[@class="main"]').first | |
path = [node] | |
begin | |
node = node.parent | |
path.unshift node | |
end until node == root | |
path.map {|n| n.name}.join " > " |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment