HTML Parsing In Ruby
HTML parsing has become quite necessary in the online world, from tools, online HTML tutorials to lint programs and crawlers, all need HTML to be parsed, Ruby has come to the front with frameworks like RoR so developers have created wonderful parsers for Ruby, in this article today we'll be looking at parsing HTML in Ruby using the Ruby gem Nokogiri.
Nokogiri being a Ruby gem is pretty straight forward to install, issue the following command on the Linux command line.
In case you encounter any issue, there is not fixed steps to resolve it, just google the error message for solutions.
In parsing HTML we'll be using CSS selectors to access & traverse DOM, follow the simple example below.
You can fetch HTML from an URL directly, and also use CSS selectors to filter elements based ob various criteria, and you can use XPath to traverse & access the DOM tree. Follow the example to get an idea.
I hope this was helpful in getting you started, enjoy and for more information visit http://nokogiri.org/
|All times are GMT +5.5. The time now is 15:58.|