Created
December 22, 2014 01:26
-
-
Save takscape/2c2d175705957ddb86b3 to your computer and use it in GitHub Desktop.
国土交通省の街区レベル位置参照情報CSVのダウンロード用URLを一括取得するCasperJSスクリプト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var casper = require('casper').create(); | |
casper.start('http://nlftp.mlit.go.jp/cgi-bin/isj/dls/_choose_method.cgi', function() { | |
this.echo(this.getCurrentUrl()); | |
this.click('input[type="submit"][value=" 都道府県単位 "]'); | |
}); | |
casper.then(function () { | |
this.echo(this.getCurrentUrl()); | |
this.click('input[id="allac"]'); | |
}); | |
casper.then(function () { | |
this.click('input[type="submit"][value=" 選 択 "]'); | |
}); | |
casper.then(function () { | |
this.echo(this.getCurrentUrl()); | |
this.click('input[id="all_gaiku1"]'); | |
}); | |
casper.then(function () { | |
this.click('input[id="all_choaza1"]'); | |
}); | |
casper.then(function () { | |
this.click('input[type="submit"][value=" 選 択 "]'); | |
}); | |
casper.then(function () { | |
this.echo(this.getCurrentUrl()); | |
this.click('input[type="submit"][value=" 同意する "]'); | |
}); | |
casper.then(function () { | |
this.echo(this.getCurrentUrl()); | |
var urls = this.evaluate(function () { | |
var ret = []; | |
var downloads = __utils__.findAll('input[type="button"]'); | |
// DownLd('3.17MB','01000-12.0a.zip','/isj/dls/data/12.0a/01000-12.0a.zip',this) | |
var re = /^DownLd\((?:'[^']*',){2}'([^']*)',this\)$/; | |
for (i=0; i<downloads.length; ++i) { | |
var onclick = downloads[i].getAttribute('onclick'); | |
var res = re.exec(onclick); | |
if (res !== null) { | |
ret.push('http://nlftp.mlit.go.jp' + encodeURI(res[1])); | |
} | |
} | |
return ret; | |
}); | |
var fs = require('fs'); | |
var content = urls.join('\n'); | |
fs.write("urls.txt", content, "w"); | |
}); | |
casper.run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
👍