如何使用Rails以其他形式填写远程表格?

时间:2021-02-22 18:21:21

Requirement: User fills out form A. Data from form A is then passed to form B on another site.

要求:用户填写表格A.表格A中的数据然后传递到另一个站点上的表格B.

1 个解决方案

#1


3  

I suggest you check out mechanize. https://github.com/tenderlove/mechanize

我建议你查看机械化。 https://github.com/tenderlove/mechanize

Say the site is http://mysite.com, and there's one field "name" that you want to fill in.

假设该网站是http://mysite.com,并且您要填写一个字段“名称”。

require 'mechanize'

def fill_out_form(name)

  # our agent
  agent = Mechanize.new

  # load mysite.com
  page = agent.get('http://mysite.com')

  # Fill out the form
  form = page.form_with(:name => 'name-form')
  form.name = name
  page = agent.submit(form)
end

then just call this from your controller

然后从控制器中调用它

FormFiller.fill_out_form(params[:name])


I adapted this form the flickr example https://github.com/tenderlove/mechanize/blob/master/examples/flickr_upload.rb

#1


3  

I suggest you check out mechanize. https://github.com/tenderlove/mechanize

我建议你查看机械化。 https://github.com/tenderlove/mechanize

Say the site is http://mysite.com, and there's one field "name" that you want to fill in.

假设该网站是http://mysite.com,并且您要填写一个字段“名称”。

require 'mechanize'

def fill_out_form(name)

  # our agent
  agent = Mechanize.new

  # load mysite.com
  page = agent.get('http://mysite.com')

  # Fill out the form
  form = page.form_with(:name => 'name-form')
  form.name = name
  page = agent.submit(form)
end

then just call this from your controller

然后从控制器中调用它

FormFiller.fill_out_form(params[:name])


I adapted this form the flickr example https://github.com/tenderlove/mechanize/blob/master/examples/flickr_upload.rb