Skip to content

Instantly share code, notes, and snippets.

@yyuu
Created May 23, 2012 09:36
Show Gist options
  • Select an option

  • Save yyuu/2774266 to your computer and use it in GitHub Desktop.

Select an option

Save yyuu/2774266 to your computer and use it in GitHub Desktop.
download java archive from oracle website
#!/usr/bin/env ruby
require 'rubygems'
require 'uri'
require 'mechanize'
$u = "PUT YOUR ORACLE USERNAME HERE"
$p = "PUT YOUR ORACLE PASSWORD HERE"
original_uri = 'http://download.oracle.com/otn/java/jdk/7u3-b04/jdk-7u3-linux-x64.tar.gz'
agent = Mechanize.new { |agent|
agent.user_agent = 'Mozilla/5.0 (Windows; U; MSIE 9.0; Windows NT 9.0; en-US)'
agent.cookie_jar.add!(Mechanize::Cookie.new('gpw_e24', '.', :domain => 'oracle.com', :path => '/', :secure => false, :for_domain => true))
}
page = agent.get(original_uri)
while true
if page.uri.host == "login.oracle.com" # login.oracle.com doesn't return proper Content-Type
page = Mechanize::Page.new(page.uri, page.response, page.body, page.code, agent) if page.is_a?(Mechanize::File)
form = page.form_with
form["ssousername"] = $u
form["password"] = $p
page = agent.submit(form)
else
page.save(File.basename(URI.parse(original_uri).path))
break
end
end
# vim:set ft=ruby :
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment