我是nodejs和puppeteer的新手,这对我来说是个问题:
我想处理多页异步,有办法吗?
{
path: "/project/:name",
name: "projectDetails",
props: true,
component: () =>
import(/* webpackChunkName: "ProjectDetails"*/ "../views/ProjectDetails")
},
// main.js
(async () => {
...
await Promise.all([
twitter.Post(text, uploadImages),
weibo.Post(text, uploadImages),
zhihu.Post(text, uploadImages)
])
...
})();
// twitter/weibo/zhihu.js
async Post() {
const browser = await puppeteer.launch({ headless: false, userDataDir: './browser' });
const page = await browser.newPage();
}
问题在于木偶只能限制2个进程,而在限制第3个进程时会捕获错误。
答案 0 :(得分:0)
const params = {
args: [
'--incognito',
'--ignore-certificate-errors',
'--no-sandbox',
'--disable-setuid-sandbox',
'--window-size=1920,1080',
'--disable-accelerated-2d-canvas',
'--disable-gpu'
// '--unlimited-storage',
// '--no-startup-window',
// '--disable-dev-shm-usage',
// '--disable-crash-reporter',
// '--disable-breakpad'
],
headless: false
};
(async () => {
...
let promiseArray=[];
promiseArray.push(twitter.Post(text, uploadImages));
promiseArray.push(weibo.Post(text, uploadImages));
promiseArray.push(zhihu.Post(text, uploadImages));
await Promise.all(promiseArray).then(()=>{
//success
}).catch((err)=>console.log(err));
...
})();
async function Post() {
return puppeteer
.launch(params)
.then(async (browser) => {
const page = await browser.newPage();
});
}