Created
August 30, 2009 02:06
-
-
Save ashmckenzie/177821 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'nokogiri' | |
require 'hpricot' | |
s = %q{<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"><html><body><input type="text" name="test" value="\" /><div id="footer"></div></body></html>} | |
selector = '#footer' | |
inner_html = 'testing' | |
# Nokogiri | |
# | |
n = Nokogiri.parse(s) | |
n.css(selector).each do |elements| | |
elements.inner_html = inner_html | |
#elements.send(:inner_html, inner_html) # nokogiri doesn't support this :( | |
end | |
puts "\n- Nokogiri" | |
puts "#{n.to_s.gsub!(/\n/, '')}\n\n" | |
# Hpricot | |
# | |
h = Hpricot(s) | |
elements = h.search(selector) | |
elements.send(:inner_html, inner_html) | |
puts "- Hpricot" | |
puts "#{h.to_s}\n\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment