Created
April 26, 2016 03:03
-
-
Save zlargon/bde6bfd1c4454a5ccddb73f44f3db766 to your computer and use it in GitHub Desktop.
fetch short url of "goo.gl"
This file contains hidden or 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'; | |
const fetch = require('node-fetch'); | |
const exec = require('child_process').execSync; | |
const ptt_url = 'https://www.ptt.cc/bbs/NBA/M.1461627008.A.3D4.html'; | |
fetch(ptt_url) | |
.then(res => { | |
if (res.status !== 200) { | |
throw new Error(`request to ${ptt_url} failed, status code = ${res.status} (${res.statusText})`); | |
} | |
return res.text(); | |
}) | |
.then(html => { | |
let map = {}; | |
html.match(/http[s]?:\/\/goo\.gl\/\w+/ig) | |
.forEach(url => { | |
// filter reproduced url | |
map[url] = true; | |
}); | |
return Object.keys(map); | |
}) | |
.then(list => { | |
list.forEach(url => { | |
// exec('open ' + url); | |
console.log(url); | |
}); | |
}) | |
.catch(console.error); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment