Created
December 23, 2011 08:03
-
-
Save noomerikal/bb27cdbf4459fc3b9686 to your computer and use it in GitHub Desktop.
mechanize nokogiri pluggable parser
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
| require 'rubygems' | |
| require 'mechanize' | |
| require 'nokogiri' | |
| class NokogiriParser < Mechanize::Page | |
| attr_reader :noko | |
| def initialize uri = nil, response = nil, body = nil, code = nil | |
| @noko = Nokogiri. | |
| super uri, response, body, code | |
| end | |
| end | |
| mech = Mechanize.new { |agent| | |
| agent.user_agent_alias = 'Mac Safari' | |
| agent.pluggable_parser.html = NokogiriParser | |
| } | |
| mech.get('http://google.com/') do |page| | |
| result = page.form_with(:name => 'f') do |search| | |
| search.q = 'FOO' | |
| end.submit | |
| result.links.each do |link| | |
| puts link.text | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment