Skip to content

Instantly share code, notes, and snippets.

@tenderlove
Created November 25, 2008 21:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tenderlove/29107 to your computer and use it in GitHub Desktop.
Save tenderlove/29107 to your computer and use it in GitHub Desktop.
require 'nokogiri'
class Nokogiri::XML::Node
def method_missing name, *args, &block
list = xpath("//#{name}")
list.length == 1 ? list.first : list
end
end
doc = Nokogiri::HTML(<<-eohtml)
<html>
<body>
<ul>
<li>one</li>
<li>two</li>
</ul>
</body>
</html>
eohtml
p doc.html.body.ul.li.first.text
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment