Created
December 28, 2015 16:52
-
-
Save 45deg/25616048f49c2bc79325 to your computer and use it in GitHub Desktop.
URLを指定してリンク一覧を抽出する
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
#!/usr/bin/env node | |
"use strict"; | |
let co = require("co"); | |
let request = require("co-request"); | |
let process = require('process'); | |
let cheerio = require('cheerio'); | |
let resolve = require('url').resolve; | |
let url = process.argv[2]; | |
if(typeof url !== "string") { | |
console.error("Usage: extract [URL]"); | |
process.exit(); | |
} | |
co(function* () { | |
let result = yield request(url); | |
let $ = cheerio.load(result.body); | |
$('a').each(function(i, e){ | |
console.log(resolve(url, $(e).attr('href'))); | |
}) | |
}).catch(function (err) { | |
console.err(err); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment