Created
November 25, 2010 20:02
-
-
Save elight/715837 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
require 'nokogiri | |
require 'open-uri' | |
io = open 'http://slashdot.org' | |
text = io.read | |
doc = Nokogiri::HTML::Document.parse(text) | |
# Just in case you didn't know, "#<some id here>" is a CSS selector for locating an HTML element by ID | |
doc.css("#top_parent a").count | |
# voila! |
Noko is your best buddy for HTML and XML parsing. It wraps libxml and is wicked fast, powerful, and elegant.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Beautiful! Thanks a ton! I'm still a total r00bn00b, but I'm learning!