我正在尝试使用机械化功能来登录网站“ vpnstaticip.com” 但我总是遇到未知错误
错误:电子邮件太长
提交后。
该错误从未在浏览器中发生
我试图提交而没有任何输入并且发生了同样的事情
require "mechanize"
$url = "https://vpnstaticip.com/create-account.php?trial=1"
$m = Mechanize.new
$page1 = $m.get($url)
$form1 = $page1.form_with(:id => "pro_form1")
$form1.field_with(:name => "name").value = "name"
$form1.field_with(:name => "email").value = "me@mail.com"
$form1.field_with(:name => "country").options[217].click #United States
$form1.field_with(:name => "username").value = "Username"
$form1.checkbox_with(:name => "terms").check
$page2 = $m.submit($form1)
$file1 = open("vpnstaticip.html","w")
$file1.write($page2.parser)
$file1.close()
答案 0 :(得分:0)
看起来像js提交的表单,但是机械化实际上不适用于js
onclick="document.getElementById('pro_form1').submit();"
更改驱动程序(可能会帮助硒或poltergeist)创建Capybara浏览器会话。
或者作为一种选择,只是尝试忽略SSL错误:
$m.verify_mode = OpenSSL::SSL::VERIFY_NONE
或者我认为,在不使用机械化的情况下,在此处使用网帖请求更好匹配,对我来说很好用:
url = URI("https://vpnstaticip.com/create-account.php?trial=1")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Post.new(url)
request["content-type"] = 'application/x-www-form-urlencoded'
request.body = "name=name&email=me%2540mail.com&country=217&username=Username&terms=1&nospam=nospam&submitted=1"
response = http.request(request)
puts response.read_body
=> ERROR: Username already exists. Try different one
此外,我无法重现“电子邮件时间过长”错误,所以请让我知道问题是否仍然存在,谢谢