Skip to content

ezkl/craft

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Craft Build Status

Craft XML and HTML into objects.

Examples

require 'craft'
require 'open-uri'

class Page < Craft
  # Use CSS selectors
  one   :title,   'title'

  # Use XPath
  many  :links,   'a/@href'

  # Perform transforms on returned nodes
  many  :images,  'img', lambda { |img| img.attr('src').upcase }
end

page = Page.parse open('http://www.google.com')

page.title #=> 'Google'
page.links #=> ['http://www.google.com/imghp?hl=en&tab=wi', ...]
page.images #=> ['/LOGOS/2012/MOBY_DICK12-HP.JPG']

class Script < Craft
  one :body, 'text()'
end

class Page < Craft
  many :scripts, 'script', Script
end

page = Page.parse open('http://www.google.com')
page.scripts[0].body #=> 'window.google=...'

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Ruby 100.0%