require 'rubygems' require 'mechanize' a = WWW::Mechanize.new { |agent| agent.user_agent_alias = 'Mac Safari' } a.get('http://www.usj.com.my/gallery/add_comment.php?set_albumName=album49&id=I&gallery_popup=true') do |page| form = page.forms.first node = form.form_node thisinp = nil node.xpath(%q"//input[not(@type) or @type!='hidden']").each do |input| next unless input[:name] if thisinp.nil? thisinp = input else puts 'replacing' input.replace(thisinp) end puts input.class puts input end puts thisinp end
Nokogiri::XML::Element <input name="commenter_name" value="" size="30"> replacing Nokogiri::XML::Element <input name="save" type="submit" value="Post comment"> <input name="commenter_name" value="" size="30">