1 Star 0 Fork 3

lebu9527/puppeteer+koa爬虫程序

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
puppeteer-pool.js 1.35 KB
一键复制 编辑 原始数据 按行查看 历史
钟鹏 提交于 2024-08-17 10:36 +08:00 . feat: 创建爬虫程序
const puppeteer = require("puppeteer");
let WSE_LIST = []; //存储browserWSEndpoint列表
let BROWSER_LIST = []; //存储browserWSEndpoint列表
const MAX_WSE = 4;
//负载均衡
const createWSEList = async () => {
for (let i = 0; i < MAX_WSE; i++) {
const browser = await puppeteer.launch({
headless: "shell",
//参数
args: [
'--disable-gpu',
'--disable-dev-shm-usage',
'--disable-setuid-sandbox',
// '--no-first-run',
'--no-sandbox',
'--no-zygote',
'--single-process'
],
//一般不需要配置这条,除非启动一直报错找不到谷歌浏览器
//executablePath:'chrome.exe在你本机上的路径,例如C:/Program Files/Google/chrome.exe'
});
let browserWSEndpoint = await browser.wsEndpoint();
BROWSER_LIST.push(browser);
WSE_LIST.push(browserWSEndpoint);
}
}
const resetWSEList = () => {
try {
BROWSER_LIST.forEach(async browser => {
await browser?.close()
})
WSE_LIST = []
BROWSER_LIST = []
} catch (error) {
WSE_LIST = []
BROWSER_LIST = []
}
}
const fetchWSEList = () => WSE_LIST
module.exports = {
createWSEList,
resetWSEList,
fetchWSEList
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/lebu2018/puppeteer_koa.git
git@gitee.com:lebu2018/puppeteer_koa.git
lebu2018
puppeteer_koa
puppeteer+koa爬虫程序
master

搜索帮助