Skip to content

Instantly share code, notes, and snippets.

@cchudant
Created September 8, 2018 23:08
Show Gist options
  • Select an option

  • Save cchudant/6ca4e1ff92128761185725c348d1a604 to your computer and use it in GitHub Desktop.

Select an option

Save cchudant/6ca4e1ff92128761185725c348d1a604 to your computer and use it in GitHub Desktop.
const fetch = require('node-fetch')
const fullUrl = 'https://bayfiles.com/W6Z6ceh8bf/rengekawai_jpg'
async function getUrl() {
const res = await fetch(fullUrl)
const text = await res.text()
const [, url] = /<a href="(https:\/\/cdn-\d{2}.+)">/.exec(text)
return url
}
const delay = t => new Promise(r => setTimeout(r, t))
void async function() {
const map = new Map()
while(map.size < 10) {
const url = await getUrl()
const cdn = +url.substring(12, 14)
map.set(cdn, url)
console.log(map)
await delay(5000)
}
}()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment