Created
March 23, 2011 21:23
-
-
Save zorn/884025 to your computer and use it in GitHub Desktop.
Playing around with mechanize to interact with websites using Ruby
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' | |
# http://mechanize.rubyforge.org/mechanize/EXAMPLES_rdoc.html | |
# http://stackoverflow.com/questions/4360043/using-wwwmechanize-to-download-a-file-to-disk-without-loading-it-all-in-memory-f | |
agent = Mechanize.new | |
page = agent.get('http://clickablebliss.com/contact.html') | |
# Print out the page as mechanize sees it | |
# pp page | |
result_page = page.form_with(:action => '/cgi-sys/cgiemail/contactform.txt') do |f| | |
f['realname'] = "Timmy Tester" | |
f['required-email'] = '[email protected]' | |
f['required-message'] = "some test message\n\nline 3 " + Time.now.to_s | |
end.submit | |
if !result_page.title.eql?('Clickable Bliss: Contact Form Successful!') | |
puts "It didn't work right" | |
pp result_page | |
else | |
puts "I think it worked. Go check email." | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment