Skip to content

dineshsprabu/ruby-cheerio

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ruby Cheerio - jQuery style HTML parser for ruby

Visit the published gem page at rubygems.org

Installing the GEM

Use 'gem install ruby-cheerio' for adding it to your gem-list

You can add 'gem ruby-cheerio' to your Gemfile and run 'bundle install'.

Sample Code

Adding ruby-cheerio to your code

require 'ruby-cheerio'

jQuery is just a variable here.

jQuery = RubyCheerio.new("<html><body><h1 class='one'>h1_1</h1><h1>h1_2</h1></body></html>")

The .find method on a cheerio object with 'selectors', which can be a class, id, element name or all together.

jQuery.find('h1').each do |head_one|
	p head_one.text
end

The .prop method can return the value of the attribute. Here 'class' is the attribute needed and 'h1' is the selector again.

p jQuery.find('h1.one')[0].prop('h1','class')

You can find some interesting code samples here: Sample Code

About

Ruby Cheerio - jQuery style HTML parser in Ruby

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages