当前,我有一个HTML站点。我通过检查chrome开发人员工具中的元素确认了这一点。
<div class="hdp-photo-carousel" style="transform: translateX(0px);">
<div class="photo-tile photo-tile-large">
我直观地看到页面打开,并且可以看到其中的项目。然后在30秒后收到此错误:
UnhandledPromiseRejectionWarning: TimeoutError: waiting for selector ".photo-tile" failed: timeout 30000ms exceeded
我在puppeteer js中的代码是:
await page.waitForSelector('.photo-tile');
有人可以告诉我我在做什么错吗?
编辑我要添加整个代码:
const pptrFirefox = require('puppeteer-firefox');
(async () => {
const browser = await pptrFirefox.launch({headless: false});
const page = await browser.newPage();
await page.goto('https://zillow.com');
await page.type('.react-autosuggest__input', '8002 Blandwood Rd. Downey, CA 90240');
await page.click('.zsg-search-button_primary');
await page.waitForSelector('.photo-tile');
console.log('did I get this far?');
})();
答案 0 :(得分:0)
每次页面内容更新时,您需要添加Page.waitForNavigation()。
(async () => {
const browser = await pptrFirefox.launch({headless: false});
const page = await browser.newPage();
const navigationPromise = page.waitForNavigation({waitUntil: "domcontentloaded"});
await page.goto('https://zillow.com');
await navigationPromise;
await page.type('.react-autosuggest__input', '8002 Blandwood Rd. Downey, CA 0240');
await page.click('.zsg-search-button_primary');
await navigationPromise;
await page.waitForSelector('.photo-tile');
console.log('did I get this far?');
})();