async function getRandomUserAgent(){
// сначала берём рандомный юзер агент
request('https://headers.scrapeops.io/v1/user-agents?api_key=my_key&num_results=1', (error, response, body) => {
if (error) {
throw new Error(error);
}
let _parsed = JSON.parse(body)
return _parsed.result[0]
});
}
async function getRandomUserAgent(){
return new Promise((resolve, reject) => {
request('https://headers.scrapeops.io/v1/user-agents?api_key=secret&num_results=1', (error, response, body) => {
if (error) {
reject(error);
}
let _parsed = JSON.parse(body);
resolve(_parsed.result[0]);
});
});
}
(async function() {
let result = await getRandomUserAgent();
console.log(result);
})();