在我编写的脚本中,我代表用户使用他们的凭据成功登录亚马逊。然后我正在尝试填写表格以输入新地址。这是我当前的代码:
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.x
或newAddress.y
任何地方,我似乎无法。
关于为什么这没有成功提交的任何想法?可能是 SSL 问题吗?