Skip to content

Instantly share code, notes, and snippets.

@45deg
Created December 28, 2015 16:52
Show Gist options
  • Save 45deg/25616048f49c2bc79325 to your computer and use it in GitHub Desktop.
Save 45deg/25616048f49c2bc79325 to your computer and use it in GitHub Desktop.
URLを指定してリンク一覧を抽出する
#!/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