I want to parse information about new products from e-commerce site by using puppeteer. When i run my code after 1-2 hours depended of number of browsers i run (if i run 2 browser after +- 1 hours) an error occured and puppeteer browsers won't spawn unitll i restart my code execution.
Error: spawn ENAMETOOLONG
Error: spawn ENAMETOOLONG at ChildProcess.spawn (internal/child_process.js:407:11) at Object.spawn (child_process.js:553:9) at BrowserRunner.start (C:\Users\Administrator\Desktop\crawler-test\node_modules\puppeteer\lib\launcher\BrowserRunner.js:51:34) at ChromeLauncher.launch (C:\Users\Administrator\Desktop\crawler-test\node_modules\puppeteer\lib\Launcher.js:64:16) at async PuppeteerExtra.launch (C:\Users\Administrator\Desktop\crawler-test\node_modules\puppeteer-extra\dist\index.cjs.js:129:25) at async getDataRestock (C:\Users\Administrator\Desktop\crawler-test\test.js:122:21) { errno: 'ENAMETOOLONG', code: 'ENAMETOOLONG', syscall: 'spawn' }
Here is a sample code:
const puppeteer = require('puppeteer-extra');
const pluginProxy = require('puppeteer-extra-plugin-proxy');
async function getData(urlNew, ...args, proxy) {
puppeteer.use(pluginProxy({
address: proxy,
port: 1050,
credentials: {
username: 'okQLjn',
password: 'vYTNDiJ24D',
}
}));
const browser = await puppeteer.launch({ args: ['--disable-dev-shm-usage'], headless: false });
const page = await browser.newPage();
await page.setCookie(...cookies)
try {
await page.goto(urlNew, {
waitUntil: 'networkidle0',
});
const data = await page.evaluate(({ ...args }) => {
//do some parsing
return prodsAndSizesAndHookProducts;
}, { ...args });
await page.close();
await browser.close();
return data;
} catch (err) {
console.log("ERROR new " + err + ' proxy: ' + proxy);
await page.close();
await browser.close();
Parser(...args)
}
}
function Parser(...args) {
if (proxiesTempArr.length == 0) {
proxiesTempArr.push(...proxies);
}
const proxy = proxiesTempArr.shift();
getData(url, ...args, proxy)
.then(result => {
if (result != undefined) {
const status = 'new product'
for (let i = 0; i < result[1].length; i++) {
Discord.sendHook(...args);
Slack.sendHook(...args);
}
console.log(status)
Parser(...args);
}
})
.catch(err => {
console.log(err + ' err new ' + new Date().toLocaleString());
Parser(...args);
})
}
Parser(...args)
While running there are some warnings such as:
MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 targetcreated listeners added to [Browser]. Use emitter.setMaxListeners() to increase limit
ERROR: The process with PID 1244 (child process of PID 7208) could not be terminated.
Reason: There is no running instance of the task.
- Puppeteer version: v3.3.0
- Platform / OS version: win64
- Node.js version: v14
I know warnings are bad but i think it's not related to an error. Will appreciate any help and thoughts.