node.js - Heroku 错误 R10(启动超时) Node 上的 Puppeteer(网页抓取应用程序)

标签 node.js heroku puppeteer

我创建了一个网络抓取应用程序,用于检查电子商务网站上的特定问题。

它的作用:

  • 循环访问页面数组
  • 检查每个页面上的条件
  • 如果满足条件 - 将页面推送到临时数组
  • 发送一封以临时数组作为正文的电子邮件

我将该函数包装在 cronjob 函数中。 在我的本地计算机上它运行良好。

这样部署:

  • headless :正确
  • '--无沙箱',
  • '--disable-setuid-sandbox'
  • 将 pptr buildpack 链接添加到 heroku 中的设置
  • slugsize 为 500 MiB 中的 259.6 MiB

没有成功。

  • 将启动超时设置为 120 秒(而不是 60 秒)

它成功了。但只跑了一次。

由于它想要每天多次运行该函数,因此我需要解决该问题。

我正在运行另一个应用程序,它使用相同的 cronjob 和通知功能,并且它可以在 heroku 上运行。

如果有人感兴趣,这是我的代码。

const puppeteer = require('puppeteer');
const nodemailer = require("nodemailer");
const CronJob = require('cron').CronJob;
let articleInfo ='';
const mailArr = [];
let body = '';

const testArr = [
    'https://bxxxx..', https://b.xxx..', https://b.xxxx..',
];

async function sendNotification() {

    let transporter = nodemailer.createTransport({
      host: 'mail.brxxxxx.dxx',
      port: 587,
      secure: false,
      auth: {
        user: '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1b737e625b793563636363" rel="noreferrer noopener nofollow">[email protected]</a>',
        pass: process.env.heyBfPW2
      }
    });
  
    let textToSend = 'This is the heading';
    let htmlText = body;
  
    let info = await transporter.sendMail({
      from: '"BB Checker" <hey@baxxxxx>',
      to: "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="601318184e4e18184e4e4e181820070d01090c4e030f0d" rel="noreferrer noopener nofollow">[email protected]</a>",
      subject: 'Hi there',
      text: textToSend,
      html: htmlText
    });
    console.log("Message sent: %s", info.messageId);
  }

async function boxLookUp (item) {
    const browser = await puppeteer.launch({
        headless: true,
        args: [
            '--no-sandbox',
            '--disable-setuid-sandbox',
          ],
    });
    const page = await browser.newPage();
    await page.goto(item);
    const content = await page.$eval('.set-article-info', div => div.textContent);
    const title = await page.$eval('.product--title', div => div.textContent);
    const orderNumber = await page.$eval('.entry--content', div => div.textContent);
    
    // Check if deliveryTime is already updated
    try {
        await page.waitForSelector('.delivery--text-more-is-coming');
    // if not
      } catch (e) {
        if (e instanceof puppeteer.errors.TimeoutError) {
          // if not updated check if all parts of set are available 
          if (content != '3 von 3 Artikeln ausgewählt' && content != '4 von 4 Artikeln ausgewählt' && content != '5 von 5 Artikeln ausgewählt'){
            articleInfo = `${title} ${orderNumber} ${item}`;
            mailArr.push(articleInfo) 
            }
        }
      }
    await browser.close();
};  

    const checkBoxes = async (arr) => {
    
    for (const i of arr) {
        await boxLookUp(i);
   }
   
   console.log(mailArr)
   body = mailArr.toString();
   sendNotification();
}

async function startCron() {
   
    let job = new CronJob('0 */10 8-23 * * *', function() {  // run every_10_minutes_between_8_and_11
        checkBoxes(testArr);
    }, null, true, null, null, true);
    job.start();
}

startCron();

最佳答案

同样的问题已经持续三天了。这里可能有帮助:https://stackoverflow.com/a/55861535/13735374

必须与 Procfile 一起完成。

关于node.js - Heroku 错误 R10(启动超时) Node 上的 Puppeteer(网页抓取应用程序),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67498169/

相关文章:

ruby-on-rails - 如何将 CarrierWave Direct 与嵌入式 Mongodb 文档和遗留 Carrierwave 文件一起使用

webgl - 使用 puppeteer 截取运行 WebGL 的页面的屏幕截图

node.js - 服务器渲染 react-router v4 passthrough if 404

javascript - socket.io 给出了两个响应,但预计只有一个

javascript - 嵌入的一个值中的多行(discord.js)

django - 如何在 heroku 服务器中配置 django-celery

node.js - 带有 apache 的 Socket.io - 套接字客户端 1 id 在连接客户端 2 时刷新

node.js - 带有 Node js的facebook messenger bot api发送多个回复

windows - 如何在 Windows 上获取 wsChromeEndpointUrl

javascript - 如何使用我的 Node js 程序中任何元素的值?