Skip to content

Instantly share code, notes, and snippets.

@Epictetus
Forked from miyagawa/yakan-hiko.rb
Created August 16, 2012 06:32
Show Gist options
  • Save Epictetus/3367364 to your computer and use it in GitHub Desktop.
Save Epictetus/3367364 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'mechanize'
require 'pry'
class Agent
def initialize(login, password)
@agent = Mechanize.new
@agent.pluggable_parser['appilcation/epub+zip'] = Mechanize::Download
@login, @password = login, password
end
def download(url)
page = @agent.get 'https://yakan-hiko.com/login.php'
form = page.form_with(:name => 'contact')
form.login_id = @login
form.pass = @password
@agent.submit form
page = @agent.get(url)
page.save("/tmp/#{page.filename}")
end
end
agent = Agent.new(ENV['YAKAN_HIKO_LOGIN'], ENV['YAKAN_HIKO_PASSWORD'])
agent.download(ARGV[0])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment