Code first
const proxys = [{
type:"HTTP",
ip:123.456.789.123
port:4399
}]
function check() {
let flag = proxys.length;
return new Promise((resolve, reject) => {
for (let i = 0; i < proxys.length; iPP) {
let proxy = proxys[i];
request({
url: "http://bbs.qcloud.com/forum-74-1.html",
proxy: `${proxy.type.toLowerCase()}://${proxy.ip}:${proxy.port}`,
method: "GET",
timeout: 1000,
headers: {
"User-Agent": UserAgent[Math.floor(Math.random() * UserAgent.length + 1) - 1]
}
}, function(error, response, body) {
if (!error && response.statusCode == 200) {
useful.push(response.request["proxy"]["href"]);
console.log("");
}
flag--;
if (flag == 0) {
resolve(useful);
}
});
}
}).then(res => {
return JSON.stringify(res);
}).catch(err => {
return err;
})
}
I want to test whether the http proxy address is available in the proxys array.
fill in the available address obtained by the above function into the browser for testing, and find that in the case of
https failed. The link to
http redirects to the home page of youdao (www.youdao.com) and shows the authentication failure.
do you have any good solutions that allow me to filter out the available proxy addresses?