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

﹥>﹥吖頭↗ 提交于 2020-01-06 08:31:28

问题


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


回答1:


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/




回答2:


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



来源:https://stackoverflow.com/questions/8436879/using-ruby-rails-to-programmatically-post-form-data-to-another-site

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!