0

在我编写的脚本中,我代表用户使用他们的凭据成功登录亚马逊。然后我正在尝试填写表格以输入新地址。这是我当前的代码:

class AmazonCrawler
  def initialize
    @agent = Mechanize.new do |agent|
      agent.user_agent_alias = 'Mac Safari'
      agent.follow_meta_refresh = true
      agent.redirect_ok = true
    end
  end

  def login
    login_url = "https://www.amazon.com/gp/css/account/address/view.html?ie=UTF8&ref_=ya_add_address&viewID=newAddress"
    @agent.get(login_url)
    form = @agent.page.forms.first
    form.email = "whatever@gmail.com"
    form.radiobuttons.last.check
    form.password = "my_password"
    dashboard = @agent.submit(form)
  end
end

class UsersController < ApplicationController

  def index
    response = AmazonCrawler.new.login
    form = response.forms[1]

    # fill out form
    form.enterAddressFullName == "Your Name"
    form.enterAddressAddressLine1 = "123 Main Street"
    form.enterAddressAddressLine2 = "Apartment 34"
    form.enterAddressCity = "San Francisco"
    form.enterAddressStateOrRegion = "CA"
    form.enterAddressPostalCode = "94101"
    form.enterAddressPhoneNumber = "415-555-1212"
    form.AddressType = "RES"
    form.enterAddressIsDomestic = "0"
    form.GateCode = ""

    new_response = form.submit( form.button_with(value: /Save.*Continue/) )
  end

end

我提交了表单,它会将我带到相同的“添加地址”表单,但没有明显的错误,页面上没有任何新内容。这new_response请求填写了相同的表格。

当我检查发布请求时,这是我得到的:

enterAddressFullName=test+user&enterAddressAddressLine1=123+Main+Street&enterAddressAddressLine2=123&enterAddressCity=san+francisco&enterAddressStateOrRegion=ca&enterAddressPostalCode=94101&enterAddressCountryCode=US&enterAddressPhoneNumber=4155551212&enterAddressIsDomestic=0&AddressType=RES&GateCode=&isDomestic=0&newAddress.x=55&newAddress.y=17&newAddress=Save+%26+Continue&addressID=&sessionId=204-4423391-1593712

对我来说最突出的是它的最后一部分:

&newAddress.x=55&newAddress.y=17&newAddress=Save+%26+Continue&addressID=&sessionId=176-3067966-1293712

我没有设置newAddress.xnewAddress.y任何地方,我似乎无法。

关于为什么这没有成功提交的任何想法?可能是 SSL 问题吗?

4

2 回答 2

0

弄清楚了。我用==而不是设置名称=导致该字段为空

于 2013-10-24T23:57:15.057 回答
0

newAddress 是按钮的名称。.x 和 .y 表示单击按钮的确切位置。表单返回您的原因有很多,很可能是它不喜欢您的某个值。

于 2013-10-19T01:12:44.570 回答