页面.直接点击木偶转到另一个页面不起作用



我试图去一个网页点击登录,这将引导我到另一个网站(这是Steam)键入用户名/密码。但当我点击指示蒸的时候,它就挂在那里了。我的代码:

try {
await page.goto("https://www.tradeit.gg", {waitUntil: "load", timeout: 0});
} catch(e) {
console.log(e)
}
try{
await Promise.all([
page.waitForSelector('a[href="https://steamtrade.gg/auth/steam"]'),
page.click('a[href="https://steamtrade.gg/auth/steam"]'),
page.waitForNavigation({ waitUntil: 'networkidle0' })
])
} catch (e) {
console.log("can not login, error: " + e);
}

我试图点击的按钮:

<ul class="navbar-nav mr-3" style="color: #c7ced4;">
<a href="https://steamtrade.gg/auth/steam" class="mr-3" onclick="if (!window.__cfRLUnblockHandlers) return false; fireLoginEvent('navbar_mainpage')">
<button class="btn btn-success steamlogin my-2 my-sm-0" type="submit"></button>
</a>
</ul>

我得到的错误:

can not login, error: TimeoutError: Navigation timeout of 30000 ms exceeded
(node:30861) UnhandledPromiseRejectionWarning: Error: No node found for selector: input[type="password"]
at Object.exports.assert (/home/danhle/Documents/Work/personalProjects/googleAdd/scrawlingApp/node_modules/puppeteer/lib/cjs/puppeteer/common/assert.js:26:15)
at DOMWorld.type (/home/danhle/Documents/Work/personalProjects/googleAdd/scrawlingApp/node_modules/puppeteer/lib/cjs/puppeteer/common/DOMWorld.js:306:21)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
at async /home/danhle/Documents/Work/personalProjects/googleAdd/scrawlingApp/app.js:31:5
(node:30861) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)

我真的需要帮助,已经好几天了…

对我来说,你把它弄得太复杂了,尽量保持简单。

下面的代码运行正常:

const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch({ headless: false });
const page = await browser.newPage();
await page.goto('https://www.tradeit.gg', { waitUntil: 'networkidle2' });
await Promise.all([
page.waitForNavigation({ waitUntil: 'networkidle2' }),
page.click('[href="https://steamtrade.gg/auth/steam"]')
]); 
await browser.close();
})();

如果你修改

,即使你的代码工作
await page.goto("https://www.tradeit.gg", {waitUntil: "load", timeout: 0});

不需要等待load事件

最新更新