会话和并发以及它们之间的关系

Sessions and concurrency and how they are related

我正在构建一个 PuppeteerCrawler,我必须登录到某个网站。但是该网站不允许多个浏览器同时使用同一个帐户。据我了解,会话是持久保存到单个 IP,但我怎样才能使该会话也对浏览器实例独占?

我还使用 10 个输入用户通过以下功能进行轮换。

exports.authenticate = async (page) => {
    const  { users }  = await Apify.getInput();
    const user = Math.round(Math.random() * 10 ); 

    let isLogged = await loggedCheck(page);

    if (!isLogged) {
        log.debug(`Cookies from cache didn't work, trying to login..`);
        await page.type('input[name="email"]', users[user].username);
        await page.type('input[name="password"]', users[user].password);
        await page.click('input[name="submit"]');
        isLogged = await loggedCheck(page);
    }

    if (!isLogged) {
        throw new Error('Didn\'t work!');        
    }
};

默认情况下,会话 IP 是浏览器实例独有的,在 PuppeteerCrawler 中,可以使用 SessionPool

管理它们

看看这个,应该会有帮助:https://sdk.apify.com/docs/guides/session-management