You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Puppeteer/NodeJS登录网站时遇错误的排查求助

无法通过Puppeteer脚本登录hibid.com的问题

我尝试使用个人凭证登录hibid.com网站,但始终收到网站返回的错误(错误截图:Login Error from website)。以下是我编写的LoginOnly.js脚本,我已尽可能添加控制台日志,但仍无法定位问题所在:

// Import necessary modules
const puppeteer = require('puppeteer');
require('dotenv').config();

(async () => {
    // Launch the browser
    const browser = await puppeteer.launch({ headless: false }); // Keep headless false for debugging

    // Open a new page (without using incognito)
    const page = await browser.newPage();

    // Set custom User-Agent and viewport
    await page.setUserAgent('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36');
    await page.setViewport({ width: 1280, height: 800 });

    // Stealth: Disable navigator.webdriver
    await page.evaluateOnNewDocument(() => {
        Object.defineProperty(navigator, 'webdriver', {
            get: () => false,
        });
    });

    // Navigate to the main page
    await page.goto('https://hibid.com');

    // Click the login link to open the modal
    try {
        // Wait for the login link to be visible and click it
        await page.waitForSelector('.login-link', { timeout: 5000 });
        await page.click('.login-link');
        console.log('Clicked login link.');

        // Wait for the modal dialog to appear
        await page.waitForSelector('form', { timeout: 5000 });
        console.log('Login modal appeared.');

        // Get all input elements inside the form
        const formInputs = await page.$$('form input');
        console.log(`Found ${formInputs.length} input fields.`);

        // Loop through the input elements and fill them based on their types
        for (const input of formInputs) {
            const inputType = await (await input.getProperty('type')).jsonValue();
            console.log(`Filling input field of type: ${inputType}`);

            // Fill based on input type
            if (inputType === 'text') {
                // Assume this is the email/username field
                await input.click();
                await input.type(process.env.HIBID_USERNAME);
                console.log('Filled in the username.');
            } else if (inputType === 'password') {
                // Assume this is the password field
                await input.click();
                await input.type(process.env.HIBID_PASSWORD);
                console.log('Filled in the password.');
            }
        }

        // Click login button
        await page.click('button.btn-login');

        // Wait for login to complete
        await page.waitForNavigation({ waitUntil: 'networkidle2' });
        console.log('Successfully logged in.');

    } catch (error) {
        console.log('Error during login:', error);
        await browser.close();
        return;
    }

    // Close the browser after login
    await browser.close();

})();

我已经尝试了多种方法和编码方式,但依旧毫无头绪,肯定存在操作误区却无法定位 :(

内容的提问来源于stack exchange,提问作者Andrew

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.18 07:57:43