Skip to content

Instantly share code, notes, and snippets.

@res0nat0r
Created November 10, 2009 18:51
Show Gist options
  • Save res0nat0r/231155 to your computer and use it in GitHub Desktop.
Save res0nat0r/231155 to your computer and use it in GitHub Desktop.
Breadcrumbs
#!/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