-
-
Notifications
You must be signed in to change notification settings - Fork 903
Home
tenderlove edited this page Sep 12, 2010
·
22 revisions
Welcome to the nokogiri wiki!
Learn how to Generate HTML.
Here is how to parse HTML:
require 'nokogiri'
doc = Nokogiri::HTML.parse(<<-eohtml)
Hello WorldI am a paragraph I am a link
eohtml
####
- Search for nodes by css
doc.css(‘p > a’).each do |a_tag|
puts a_tag.content
end####
- Search for nodes by xpath
doc.xpath(‘//p/a’).each do |a_tag|
puts a_tag.content
end####
- Or mix and match.
doc.search(‘//p/a’, ‘p > a’).each do |a_tag|
puts a_tag.content
end