await products?.map(async ilan => {
(async () => {
try {
const email = "";
const password = "";
const title = ilan.title;
const location = ilan.Country[random].country;
const categories = ilan.category;
const link = ilan.link;
const description = ilan.description;
const manufacturer = ilan.manufacturer;
const model = ilan.model;
const year = ilan.year;
console.log('title', title)
const browser = await puppeteer.launch({
// devtools: true
// defaultViewport: null,
// headless: true,
// executablePath: '/usr/bin/chromium-browser',
// args: ['--no-sandbox'],
});
const page = await browser.newPage();
await page.goto('');
// await page.screenshot({ path: 'example.png' });
// ! Email
async function input(focus, deger) {
await page.focus(focus)
await page.keyboard.type(deger)
}
await input('#user_email', email)
await input('#user_password', password)
// ! Submit
await page.click('input[type="submit"]')
await page.waitForTimeout(10000)
// ! Title
await input('input[id="api_listing_title"]', title)
// ! Location
await input('input[id="api_listing_location"]', location)
// ! Categories
await input('input[type="search"]', categories)
await page.click('li[role="option"]')
// ! Youtube Link
await input('input[id="youtube_link"]', link)
// ! Description
await input('textarea[name="api_listing[description]"]', description)
// ! Manufacturer
await input('input[name="api_listing[manufacturer]"]', manufacturer)
await input('input[name="api_listing[model]"]', model)
await input('input[name="api_listing[year]"]', year)
await page.select('#api_listing_condition', 'new')
// ! Resim
const inputUploadHandle = await page.$('input[type=file]');
ilan.images?.map(async image => {
await inputUploadHandle.uploadFile(image.path)
})
await page.waitForTimeout(10000)
await page.click('input[name="commit"]')
await page.waitForTimeout(15000)
await browser.close();
} catch (error) {
console.log("🌵💜🐢 error", error)
res.json({ message: 'error' })
}
})(ilan);
})
(node:20436) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 exit listeners added to [process]. Use emitter.setMaxListeners() to increase limit
(Use `node --trace-warnings ...` to show where the warning was created)
(node:20436) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 SIGINT listeners added to [process]. Use emitter.setMaxListeners() to increase limit
(node:20436) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 SIGTERM listeners added to [process]. Use emitter.setMaxListeners() to increase limit
(node:20436) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 SIGHUP listeners added to [process]. Use emitter.setMaxListeners() to increase limit
程序运行时出现此错误
@pguardiario 给出的答案也对我有用。
建议:
try {
...
} catch (...) {
...
} finally {
await browser.close();
}