看起來最新版本的jdk可以通過wget下載,但不能通過檔案中的文件下載。 因此,我使用casper.js腳本登錄到Oracle並進行下載。
以下是我的腳本下載日文版jdk8u121。當前腳本只會嘗試下載,但在重定向時會失敗。我正在使用download.sh bash腳本掃描日誌以獲取帶有會話參數的url,並使用wget執行實際下載。
你需要更換< 用戶名>和< 密碼>與有效問卷登錄到Oracle的網站。
的jdkTag和jdkFileLink變化值,以獲得您想要下載的JDK版本。
oraclejdk.js
var casper = require('casper').create({
verbose: true,
logLevel: 'info', // debug
pageSettings: {
userAgent: "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36",
loadImages: false,
loadPlugins: false
}
});
// login info
var loginUrl='http://www.oracle.com/webapps/redirect/signon?nexturl=https://www.oracle.com/technetwork/java/javase/downloads/java-archive-javase8-2177648.html';
var username='<username>';
var password='<password>';
// accept license page info
var jdkUrl='http://www.oracle.com/technetwork/';
var jdkTag='jdk-8u121-oth-JPR';
// download jdk info
var jdkFileLink='jdk-8u121-oth-JPRXXXjdk-8u121-linux-x64.tar.gz';
// open login page
casper.start(loginUrl);
casper.thenEvaluate(function(username, password) {
// this.capture('loginPage.png', {top:0, left:0, width:600, height:800});
document.querySelector("#sso_username").value = username;
document.querySelector("#ssopassword").value = password;
doLogin(document.LoginForm);
}, {
username: username,
password: password
});
// login to oracle site
casper.then(function() {
this.waitForUrl(jdkUrl, function() {
// this.capture('jdkPage.png', {top:0, left:0, width:1200, height:800});
this.evaluate(function(jdkTag) {
disableDownloadAnchors(document, false, jdkTag);
hideAgreementDiv(document, jdkTag);
writeSessionCookie('oraclelicense', 'accept-securebackup-cookie');
}, {
jdkTag: jdkTag
});
}, null, null, 5000);
});
// accept license
casper.then(function() {
this.waitFor(function checkLink() {
return this.evaluate(function(jdkTag) {
return (document.getElementById('agreementDiv' + jdkTag).getAttribute('style') === 'visibility: hidden;');
}, {
jdkTag: jdkTag
});
}, function then() {
// this.capture('acceptedLicense.png', {top:0, left:0, width:1200, height:800});
downlink = this.evaluate(function(jdkFileLink) {
var jdkElement = document.getElementById(jdkFileLink);
if (jdkElement) {
var jdkLink = jdkElement.getAttribute("href");
jdkElement.click();
return jdkLink;
}
}, {
jdkFileLink: jdkFileLink
});
}, null, 5000);
});
casper.run();
download.sh
#!/bin/bash
url=$(casperjs --web-security=no oraclejdk.js |grep "http://download.oracle.com/otn/java/jdk" $() | sed -e 's/^.*: //')
jdk=$(echo "${url}" | sed -e 's/^.*jdk-/jdk/' |sed -e 's/?.*//')
wget -O "${jdk}" "${url}"