我使用 Puppeteer 进行网页抓取,并使用我制作的一个小型 NodeJs Web 应用程序。该网络应用程序托管在 Heroku 上并使用jontewks/puppeteer-heroku-buildpack
到作品。
我面临的问题是,由于 Heroku 大小限制,我的应用程序不再构建:
Compiled slug size: 537.4M is too large (max is 500M).
我尝试了几件事:
- Using Firefox instead of Chromium
- 这对我来说是“不行”的,因为puppeteer/firefox 的当前问题 https://github.com/puppeteer/puppeteer/issues/6359:
- Reducing the size of Chromium by removing the file interactive_ui_tests.exe https://github.com/puppeteer/puppeteer/issues/842
- 我无法执行此操作,因为 Heroku 使用 Linux 而不是 Windows,并且 Linux Chromium 发行版中不存在此文件
- Using
headless_shell
instead of Chromium
- 我被这个问题困住了(就像here https://stackoverflow.com/questions/68639229/using-puppeteer-with-headless-shell)因为我不明白如何让它发挥作用。我找到了要使用的文件here https://github.com/puppeteer/puppeteer/issues/3140,但我面临着与 07/09/2018 的评论相同的问题
- Using Playwright instead of Puppeteer
- 这可能是一个解决方案,但我正在使用类似的东西
puppeteer-extra
and puppeteer-extra-plugin-stealth
,所以改变我很烦恼
- Reducing the size of Chromium by removing the folder
locales
- Using an older version of Puppeteer (
2.1.1
), which is using an older version Chromium who was slighlty lighter
- 使用命令
heroku repo:gc -a myapp
and heroku builds:cache:purge -a myapp
我的最后三点将我的鼻涕虫的大小减小到490M
。所以我的应用程序正在运行,但对于(近期)未来来说并不是很好,就像拥有最新的 Puppeteer 版本一样。
所以我在这里寻求帮助,因为我目前没有更多的想法。
非常感谢您的帮助????
最后,我最终使用了 Playwright。
With 这个构建包 https://elements.heroku.com/buildpacks/playwright-community/heroku-playwright-buildpack,我的应用程序的构建只有 250Mb!
以下是我遵循的几个步骤:
-
使用 NPM 安装playwright-chromium
仅下载 Chromium。
-
Set PLAYWRIGHT_BUILDPACK_BROWSERS
环境变量为chromium
在 Heroku 中仅安装 Chromium 依赖项。
-
在 Heroku 中将此构建包放在 Node.js 构建包之前。
-
With 这个伎俩 https://github.com/berstend/puppeteer-extra/issues/454#issuecomment-917437212你可以使用大部分的东西puppeteer-stealth
.
-
如果需要,您可以像 Puppeteer 中那样阻止资源:
await page.route('**/*', route => ([
'stylesheet',
'image',
'media',
'font',
// 'script',
'texttrack',
'xhr',
'fetch',
'eventsource',
'websocket',
'manifest',
'other',
].includes(route.request().resourceType()) ? route.abort() : route.continue()))
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)