Created
September 8, 2018 23:08
-
-
Save cchudant/6ca4e1ff92128761185725c348d1a604 to your computer and use it in GitHub Desktop.
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
| 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