简体   繁体   English

Ruby 机械化 405 Net::HTTPMethodNotAllowed 错误,同时抓取 Fedex 计费

[英]Ruby Mechanize 405 Net::HTTPMethodNotAllowed Error While Scraping Fedex Billing

I have a script that goes into Fedex Billing each week when they mail me my invoice, digs out information and posts it to xpenser.com.我有一个脚本,每周他们都会将我的发票寄给我,挖掘信息并将其发布到 xpenser.com 时进入 Fedex Billing。 After the recent Fedex Billing site redesign, when I run this code:在最近的 Fedex Billing 站点重新设计之后,当我运行此代码时:

  agent = Mechanize.new
  page = agent.get 'http://fedex.com/us/fcl/pckgenvlp/online-billing/'
  form = page.form_with(:name => 'logonForm')
  form.username = FEDEX['username']
  form.password = FEDEX['password']
  page = agent.submit form
  pp page

I receive this error:我收到此错误:

Mechanize::ResponseCodeError: 405 => Net::HTTPMethodNotAllowed

I see there is a javascript auth function that seems to build a URL that sets hidden variables.我看到有一个 javascript auth function 似乎构建了一个设置隐藏变量的 URL。 I've tried to pass various combinations of variable strings in without success.我试图传递变量字符串的各种组合但没有成功。

While Mechanize doesn't support javascript, it will pass in variable strings and if you hit the correct one, you can auth that way.虽然 Mechanize 不支持 javascript,但它会传入可变字符串,如果您点击正确的字符串,您可以通过这种方式进行身份验证。 I'm hoping to do that here.我希望在这里做到这一点。

Using mechanize-1.0.0 the following works:使用 mechanize-1.0.0 以下作品:

  agent = Mechanize.new
  page = agent.get 'http://fedex.com/us/fcl/pckgenvlp/online-billing/'
  form = page.form_with(:name => 'logonForm')
  form.username = FEDEX['username']
  form.password = FEDEX['password']
  form.add_field!('field_name', 'Page$2')
  page = agent.submit form
  pp page

try this.尝试这个。 it may help you它可以帮助你

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM