javascript - Puppeteer:setDefaultNavigationTimeout 为 0 仍然超时
问题描述
每次我运行这个脚本都会超时。setDefaultNavigationTimeout
真的可以防止超时吗?
我正在浏览大约 26 个 URL,每个页面都有大量图像。无法想象 Puppeteer 不能仅仅因为图像太重就无法处理这些页面?
const url = 'test.com';
const jsonReturn = [];
async function runScraper() {
const browser = await puppeteer.launch(prodConfig);
const page = await browser.newPage({
timeout: 0
});
page.setDefaultNavigationTimeout(0);
await page.goto(url, { waitUntil: 'domcontentloaded' });
await page.waitForSelector('.featured-shows-featured-show');
let featuredShowsURLs = await page.$$eval('.featured-shows-featured-show > a', (links) => {
return links.map(link => {
return link.href;
});
});
featuredShowsURLs = _.uniq(featuredShowsURLs)
for (const featuredShowsURL of featuredShowsURLs) {
const page = await browser.newPage({
timeout: 0
});
try {
await page.goto(featuredShowsURL);
await page.waitForSelector('.show-title');
} catch (e) {
featuredShowsURL;
debugger;
}
const showTitle = await findAndReturnSelectorText('.show-title', page);
const showDates = await findAndReturnSelectorText('.show-dates', page);
const showLocation = await findAndReturnSelectorText('.show-location', page);
const showGallery = await findAndReturnSelectorText('.entity-link', page);
const showDetail = await findAndReturnSelectorText('.show-press-release', page);
const newItem = {
showTitle,
showDates,
showLocation,
showGallery,
showDetail,
};
const id = hash(newItem);
jsonReturn.push({
...newItem,
id
});
}
await browser.close();
}
runScraper();
解决方案
推荐阅读
- python - 如何使用记事本打开文本文件?
- c# - C# 项目,编译器抱怨缺少对 log4net 的引用
- sed - 如果有方括号,sed replace 无法替换字符串
- powershell - 如何通过 Azure DevOps Release Pipeline 中的 Azure Powershell 更新暂存槽的 IP 白名单?
- c# - 当我只想要一个时引用了两个版本的控件
- java - 安卓应用、Android 8(.1)、90% 华为设备中的 ANR 和崩溃
- jquery - 1 个抽屉打开时的切换逻辑
- mysql - MySQL 触发器错误:根据另一个表更新或插入更新一个表的字段值
- performance - 涡轮增压 Ansible 剧本
- javascript - 如何在特定数字处停止 javascript 计数器