简体   繁体   English

Puppeteer 不会在 heroku 上评估网络应用程序

[英]Puppeteer does not evaluate web-app on heroku

I'm using puppeteer on my telegram bot to fetch stuff from the web.我在我的电报机器人上使用 puppeteer 从网络上获取东西。 Locally, it's all work just fine, but here is the catch:在本地,一切正常,但这里有一个问题:

When trying to fetch the URL's HTML, the given response is not the HTML file, but the web app with all the js files.尝试获取 URL 的 HTML 时,给定的响应不是 HTML 文件,而是包含所有 js 文件的 Web 应用程序。 On my local machine - I'm getting the HTML file with all needed links.在我的本地机器上 - 我得到了包含所有需要链接的 HTML 文件。

That's my code:那是我的代码:

 return await puppeteer.launch({ args: ['--no-sandbox', '--disable-setuid-sandbox'], headless: true, }).then(async browser => { const page = await browser.newPage() page.setJavaScriptEnabled(true) await page.goto(targetUrl) await page.waitForTimeout(2000) const data = await page.$$eval(SELECTORS, (res) => { return res.map(r => { return r.getAttribute('ATRR') }) }) as never as string[] ....... })

PS -------------- already added this repo to Heroku: PS -------------- 已经将此 repo 添加到 Heroku:

https://github.com/jontewks/puppeteer-heroku-buildpack

Apparently, when you are using puppeteer-extra , you need to install puppeteer library too.显然,当您使用puppeteer-extra ,您还需要安装puppeteer库。

For some reason, they both depend BUT not auto-installed, so the Chromium engine didn't install on Heroku, and it does explain how it does on my local machine - which has it by default.出于某种原因,它们都依赖但不是自动安装的,所以 Chromium 引擎没有安装在 Heroku 上,它确实解释了它在我的本地机器上是如何运行的 - 默认情况下有它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM