我正在创建一个Web应用程序,该应用程序使用Microsoft Graph侦听传入的电子邮件,选择一些复选框,然后提交一个表单。流程如下:
代码如下:
exports.itsTimeToVulture = async (droppedShifts) => {
const browser = await puppeteer.launch({
args: ['--no-sandbox', '--disable-setuid-sandbox']
});
const page = await browser.newPage();
await page.goto('https://scheduler.engr.wisc.edu/worklocation/detail/1-' + moment(droppedShifts[0].date).format('YYYY-MM-DD'));
await page.type('#j_username', process.env.USER);
await page.type('#j_password', process.env.PASS);
await page.click('button[type=submit]');
await page.waitForSelector('.footer').then(() => {
return page.$$eval('.timeslot', (timeslots, week) => {
week.forEach((day, index) => {
if (day) {
day.forEach(shift => {
timeslots[index].children.item(shift).querySelector('input[name*=schedadd]').setAttribute('checked', true);
});
}
});
}, getIndices(droppedShifts));
});
await page.click('input[type=submit]');
await browser.close()
};
最初,我尝试使用page.waitForNavigation()
,但是这给出了一个错误。我决定使用page.waitForSelector()
,它可以在本地服务器上完美运行。
我遇到的问题是在使用Heroku时。我已经安装了puppeteer-heroku-buildpack
和node.js
buildpack。但是waitForSelector()
由于某种原因而超时。这是我的日志中的错误:
{ TimeoutError: waiting for selector ".footer" failed: timeout 30000ms exceeded
info app web.1 at new WaitTask (/app/node_modules/puppeteer/lib/DOMWorld.js:561:28)
info app web.1 at DOMWorld._waitForSelectorOrXPath (/app/node_modules/puppeteer/lib/DOMWorld.js:490:22)
info app web.1 at DOMWorld.waitForSelector (/app/node_modules/puppeteer/lib/DOMWorld.js:444:17)
info app web.1 at Frame.waitForSelector (/app/node_modules/puppeteer/lib/FrameManager.js:628:47)
info app web.1 at Frame.<anonymous> (/app/node_modules/puppeteer/lib/helper.js:111:23)
info app web.1 at Page.waitForSelector (/app/node_modules/puppeteer/lib/Page.js:1046:29)
info app web.1 at exports.itsTimeToVulture (/app/helpers/scraper.js:17:14)
info app web.1 at process._tickCallback (internal/process/next_tick.js:68:7) name: 'TimeoutError' }
我真正感到困惑的是,此设置在localhost上运行良好,但在heroku上失败。一些帮助,将不胜感激。
答案 0 :(得分:0)
我有同样的错误,这对我有用:
await page.goto("https://www.my-web.com", {timeout: 60000, waitUntil: 'domcontentloaded'})