Skip to content

Instantly share code, notes, and snippets.

@wtnabe
Created March 2, 2009 01:46
Show Gist options
  • Save wtnabe/72574 to your computer and use it in GitHub Desktop.
Save wtnabe/72574 to your computer and use it in GitHub Desktop.
=begin
Mechanize debug 用の wrapper
LICENSE : two-clause BSD
=end
def get( uri )
if ( @agent.log )
@agent.log.info( "GET #{uri}" )
end
page = @agent.get( uri )
if ( @debug )
page.save_as( File.join( PAGE_DIR, page.filename ) )
File.open( File.join( PAGE_DIR, page.filename + '.mech' ), 'wb' ) { |f|
f.write( page.inspect )
}
end
return page
end
def submit( form )
if ( @agent.log )
@agent.log.info( "submit #{form.to_s}" )
end
page = @agent.submit( form )
if ( @debug )
page.save_as( File.join( PAGE_DIR, page.filename ) )
File.open( File.join( PAGE_DIR, page.filename + '.mech' ), 'wb' ) { |f|
f.write( page.inspect )
}
end
return page
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment