ChrisWesAllen
ChrisWesAllen

Reputation: 4975

Using Ruby/Rails To Programmatically Post Form Data To Another Site

I'm trying to figure out a way to automate posting data on this site which does not have an API and thankfully not a captcha as well.

For example there is a form here => http://www.austinchronicle.com/gyrobase/EventSubmission

By examining the form I can figure out that the Name text box is setup as follows......

<input type="text" name="Name" id="EventName" value="" class="rejectPipe">

Using Ruby/Rails is there a way I can programmatically POST to the form on that page through the controller or in a rake task?

I sniffed out some links like => http://biodegradablegeek.com/2008/04/how-to-post-form-data-using-ruby/ and that seems to sort of explain the basic premise but what about inserting data into the time control or the drop down select boxes on another site? Or pretty much anything more complicated than inserting a string into an input box

Upvotes: 0

Views: 1472

Answers (2)

David Sulc
David Sulc

Reputation: 25994

Your best bet is to use something like Mechanize. I've written a blog post on a related subject (uploading data with Mechanize) : http://davidsulc.com/blog/2011/11/13/uploading-data-using-mechanize/

Alternatively, if you want to see the page while information is being entered, you could user Selenium http://davidsulc.com/blog/2011/11/27/automating-web-site-interactions-with-selenium/

Upvotes: 4

Tony
Tony

Reputation: 19181

You can use Typhoeus

For datetime selects you need conform to Rails protocol. Just pop open the source of the page and look at the names of their elements and use the same structure when posting. Do the same with select boxes

Upvotes: 1

Related Questions