Created
November 8, 2019 22:19
-
-
Save lethern/18fcbd4e72be2d89635cfc98765591f8 to your computer and use it in GitHub Desktop.
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
const request = require('request'); | |
const cheerio = require('cheerio'); | |
const fs = require('fs'); | |
const util = require('util'); | |
async function load(){ | |
let url = 'https://somesite'; | |
let body = await downloadFile(url); | |
let $ = cheerio.load(body); | |
} | |
function request_promise(url){ | |
return new Promise(function(resolve, reject) { | |
try{ | |
request(url, function(err, resp, body){ | |
if(err){ | |
reject(err); | |
return; | |
} | |
resolve(body); | |
}); | |
}catch(e){ | |
reject(e); | |
} | |
}); | |
} | |
async function downloadFile(url){ | |
let body = await request_promise(url); | |
return body; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment