0

I am trying to login to my vimeo account using Mechanize in order to scrape hundreds of video titles and urls. Here is my code:

 task :import_list => :environment do
  require 'rubygems'
  require 'mechanize'

    agent = Mechanize.new
    agent.user_agent = "Mac Safari"

    puts "Logging in..."
    page = agent.get("http://vimeo.com/log_in")
    form = page.forms[0]
    form.fields[0].value = 'sample@email.com'
    form.fields[1].value = 'somepassword'
    page = agent.submit(form)

  pp page

end

and my error message:

401 => Net::HTTPUnauthorized

This is running through a rake task if it matters at all. Any ideas?

sottenad
  • 2,646
  • 2
  • 16
  • 18

4 Answers4

1

Not sure how to do it with Mecnanize but here is code to do it with Capybara:

require 'capybara/dsl'
require 'selenium-webdriver'

Capybara.run_server = false
Capybara.default_driver = :selenium

class Vimeo
    include Capybara::DSL

    def go
        visit "https://vimeo.com/log_in"
        fill_in "email",    :with => "ivan.bisevac@gmail.com"
        fill_in "password", :with => "strx8UnK0a-"
        find("span.submit > input").click
    end
end

v = Vimeo.new
v.go

Also, Capybara is better for scraping javascript sites.

Иван Бишевац
  • 13,811
  • 21
  • 66
  • 93
1

my first thought was:

Vimeo login does not work without JavaScript, so it's not possible to login with Mechanize.
To test my bold statement:

without javascript

  • disable javascript for all sites in your browser
  • try to login ( fill out the form in your browser like you normally do )
  • you'll get an unauthorized message on the resulting page

with javascript

  • enable javascript
  • everything works as expected

update

Vimeo.com uses the following querystring when logging in.
Gonna try and post the string manually with Mechanize.

action=login&service=vimeo&email=your-email&password=your-password&token=k7yd5du3L9aa5577bb0e8fc

update 2

I've got a Ruby Rake task that logs in to a Vimeo Pro account
and reads the HTTP Live Streaming link from a video settings page.

update 3

I've posted a working Ruby Rake task: https://gist.github.com/webdevotion/5635755.

Community
  • 1
  • 1
Webdevotion
  • 1,223
  • 13
  • 24
0

It seems that authorization give something 'token'

http header part: action=login&service=vimeo&email=your_mail&password=asfsdfsdf&token=51605c24c92a4d4706ecbe9ded7e3851

0

Have you tried using the official Vimeo API?

John Douthat
  • 40,711
  • 10
  • 69
  • 66