Search code examples
rubymechanizefedex

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. After the recent Fedex Billing site redesign, when I run this code:

  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. 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. I'm hoping to do that here.


Solution

  • Using mechanize-1.0.0 the following works:

      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