node.js - 是否可以更改新任务的代理
问题描述
我只是想知道是否可以更改新任务的代理,我无法确定是否或如何完成。
我试图搜索是否可以完成,但我找不到任何东西。
const { Cluster } = require("puppeteer-cluster");
const getProxy= require("./models/get-proxy.js");
const timeout = ms => new Promise(resolve => setTimeout(resolve), ms);
(async () => {
const proxy = await getProxy();
const type = socks[0].Type[0] == "https" ? "https" : "http";
const pro = type + "://" + proxy[0].Ip + ":" + proxy[0].Port;
console.log('proxy:', pro);
const cluster = await Cluster.launch({
concurrency: Cluster.CONCURRENCY_BROWSER,
maxConcurrency: 1,
puppeteerOptions: {
headless: true,
args: [
"--no-sandbox",
"--disable-setuid-sandbox",
`--proxy-server=${pro}`
]
}
});
await cluster.task(async({ page, data: url }) => {
await page.goto(url);
console.log('going to url:', url);
const data = await page.evaluate(() => {
return {
ip: document.body.innerText,
}
});
console.log('data:', data);
});
try {
for (;; await timeout(10000)) {
await cluster.execute('https://api.myip.com');
await cluster.execute('https://api.myip.com');
await cluster.execute('https://api.myip.com');
// More urls
await cluster.idle();
await cluster.close();
}
} catch (error) {
console.log('error:', error.message);
}
})();
我想要实现的是在每个循环完成后更改代理,但我似乎无法弄清楚如何或是否可以完成。
解决方案
推荐阅读
- php - 我在数据表中添加了分页,但表记录重复
- next.js - 如何创建不刷新标题和菜单的 SPA 网站
- blazor-server-side - 为什么服务器端 Blazor 需要将所有 .NET dll 下载到浏览器?
- excel - 将定期日历会议转换为 Excel
- flutter - Flutter:如何从单独的 Widget 方法调用 onPressed() 中的 setState()
- mongodb - 无法使用 mongodb 对聚合中的分组数据进行排序
- excel - 将字符数组从 FORTRAN DLL 传递到 Excel VBA
- python - 您如何从 Alexa 设备获取原始语音输入
- typo3 - TYPO3 CMS v7:弃用日志:由于更改了字段“pi_flexform”,更改了 TCA 表“tt_content”类型“搜索”的 showitem 字符串
- java - Exoplayer 2.10.3 用java实现