使用 Ruby/Rails 以编程方式将表单数据发布到另一个站点 [英] Using Ruby/Rails To Programmatically Post Form Data To Another Site

查看:47
本文介绍了使用 Ruby/Rails 以编程方式将表单数据发布到另一个站点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试找出一种方法来自动在此站点上发布数据,该站点没有 API,幸好也没有验证码.

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.

例如这里有一个表格 => http://www.austinchronicle.com/gyrobase/EventSubmission

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

通过检查表单我可以发现 Name 文本框设置如下......

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">

使用 Ruby/Rails 有没有一种方法可以通过控制器或在 rake 任务中以编程方式 POST 到该页面上的表单?

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?

我嗅出了一些链接,例如 => http://biodegradablegeek.com/2008/04/how-to-post-form-data-using-ruby/这似乎可以解释基本前提,但是如何将数据插入时间控件或另一个站点上的下拉选择框呢?或者几乎任何比将字符串插入输入框更复杂的事情

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

推荐答案

最好的办法是使用 Mechanize 之类的东西.我写了一篇关于相关主题的博客文章(使用 Mechanize 上传数据):http://davidsulc.com/blog/2011/11/13/uploading-data-using-mechanize/

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/

或者,如果您想在输入信息时查看页面,您可以使用 Selenium http://davidsulc.com/blog/2011/11/27/automating-web-site-interactions-with-selenium/

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/

这篇关于使用 Ruby/Rails 以编程方式将表单数据发布到另一个站点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆