Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Home

tenderlove edited this page · 19 revisions

Welcome to the nokogiri wiki!

Learn how to “Generate HTMLGenerate.

Here is how to parse HTML:


require 'nokogiri'

doc = Nokogiri::HTML.parse(<<-eohtml)


Hello World

This is an awesome document

I am a paragraph I am a link

eohtml

####

  1. Search for nodes by css
    doc.find_by_css(‘p > a’).each do |a_tag|
    puts a_tag.content
    end

####

  1. Search for nodes by xpath
    doc.find_by_xpath(‘//p/a’).each do |a_tag|
    puts a_tag.content
    end

####

  1. Or mix and match.
    doc.search(‘//p/a’, ‘p > a’).each do |a_tag|
    puts a_tag.content
    end

Something went wrong with that request. Please try again.