puppeteer官方Docker镜像:"https://pptr.nodejs.cn/guides/docker" (https://link.segmentfault.com/?enc=AnfmLzTduR5bBUnSvVyycw%3D%3D.OYOLZxiap7E%2BO9UTvxFX6zj%2FKpPhh0fNsPPXtEDssN6BNANqYGHavfKiMSGH4H5x) 现在我的需求是使用"express"创建接口,当调用接口传递链接,再puppeteer访问链接进行截图,截图后把截图上传阿里Oss,返回上传阿里Oss后的图片链接 我的想法是再打包一次: "image.png" (https://wmprod.oss-cn-shanghai.aliyuncs.com/images/20250104/91ecdd52b97ba274db31f9af1d180daa.png) FROM ghcr.io/puppeteer/puppeteer 把官方镜像打包进行我们自己的Dockerfile,请大佬们这样可行吗?这个Dockerfile配置应该怎么写?请大佬指点下
我的Dockerfile配置: FROM ghcr.io/puppeteer/puppeteer:latest EXPOSE 4000 # 设置工作目录 WORKDIR /yice RUN chmod -R 777 /yice # # 复制源码 COPY ./dist /yice/dist COPY ./scripts /yice/scripts COPY ./.env /yice/ COPY ./package.json /yice COPY ./static /yice/static COPY ./tsconfig.json /yice/ COPY ./tsconfig.build.json /yice/ COPY ./node_modules /yice/node_modules CMD npm run start:prod 报错信息: "image.png" (https://wmprod.oss-cn-shanghai.aliyuncs.com/images/20250103/aa4df9d9d8f7e3ee94f62825f2191e56.png) 我已经尝试过以下几种方法: * Dockerfile配置中添加"RUN chmod -R 777 /yice" * Dockerfile配置添加 "USER root",它会报: "image.png" (https://wmprod.oss-cn-shanghai.aliyuncs.com/images/20250103/add04e0ca3e42672921842849a67a692.png) 找不Chrome,然后因为ghcr.io/puppeteer/puppeteer:latest镜像切换的用户名为"pptruser",所以我手动在代码里给puppeteer配置"executablePath: '/home/pptruser/node_modules/chrome' ",它又报找不到 "image.png" (https://wmprod.oss-cn-shanghai.aliyuncs.com/images/20250103/dc8b3c6e1d2edae81be0900d53ff74ed.png) * Dockerfile配置添加 "USER pptruser",它还是报: "image.png" (https://wmprod.oss-cn-shanghai.aliyuncs.com/images/20250103/aa4df9d9d8f7e3ee94f62825f2191e56.png) 请问有没有大佬指点下?感谢🙏了
大佬们,我使用puppeteer里的方法**$$eval** 去爬一下页面的数据,结果发现引入的nanoid不能使用,刚开始还以为是nanoid不支持commonJS写法导致的,结果调试发现在eval函数外使用可以打印成功,eval里使用就报错了 注意:$$eval返回一个promise async callback(pg) { console.log(nanoid());//这里能打印出来 const imgList = await pg.$$eval('div.swiper-wrapper>div.swiper-slide>div>img', els => els.map((el, index) => { return { imgUrl: el.src, alt: '图片', id: index, imgKey:nanoid()//这里不能使用nanoid } })) || [] return imgList } 报的错误: node:internal/process/promises:279 triggerUncaughtException(err, true /* fromPromise */); ^ Error [ReferenceError]: nanoid is not defined pptr:$$eval;Object.callback%20(D%3A%5C%E9%A1%B9%E7%9B%AE%5C%E7%88%AC%E8%99%AB%E7%B3%BB%E7%BB%9F%5Ccrawler%5Ccrawlers%5Cslider.js%3A8%3A34):6:24 at $$eval ($$eval at Object.callback (D:\项目\爬虫系统\crawler\crawlers\slider.js:8:34), :5:23) at $$eval ($$eval at Object.callback (D:\项目\爬虫系统\crawler\crawlers\slider.js:8:34), :0:12) at ExecutionContext.#evaluate (D:\项目\爬虫系统\crawler\node_modules\puppeteer-core\lib\cjs\puppeteer\common\ExecutionContext.js:254:55) at async ExecutionContext.evaluate (D:\项目\爬虫系统\crawler\node_modules\puppeteer-core\lib\cjs\puppeteer\common\ExecutionContext.js:151:16) at async CDPJSHandle.evaluate (D:\项目\爬虫系统\crawler\node_modules\puppeteer-core\lib\cjs\puppeteer\common\JSHandle.js:48:16) at async Promise.all (index 0) at async CDPElementHandle.$$eval (D:\项目\爬虫系统\crawler\node_modules\puppeteer-core\lib\cjs\puppeteer\api\ElementHandle.js:227:26) at async Object.callback (D:\项目\爬虫系统\crawler\crawlers\slider.js:8:25) at async module.exports (D:\项目\爬虫系统\crawler\libs\crawler.js:10:18) 有大佬知道为什么吗
pt.launch({ // slowMo: 250, devtools: true, headless: false, // executablePath: '/path/to/Chrome', args: [ '--disable-features=site-per-process', '--disable-notifications=true' ], ignoreDefaultArgs: ['--enable-automation'], // devtools: false, }).then(async browser => { const page = await browser.newPage() 在这里打断点动态执行
我想使用"puppeteer"进行截图,然后使用docker将项目打包成镜像,但运行镜像时报这个错: "image.png" (https://wmprod.oss-cn-shanghai.aliyuncs.com/images/20250105/90039ba75af92f54c7d78c39bacf358b.png) 我已经执行过它 yum install pango.x86_64 libXcomposite.x86_64 libXcursor.x86_64 libXdamage.x86_64 libXext.x86_64 libXi.x86_64 libXtst.x86_64 cups-libs.x86_64 libXScrnSaver.x86_64 libXrandr.x86_64 GConf2.x86_64 alsa-lib.x86_64 atk.x86_64 gtk3.x86_64 -y Dockerfile文件: "image.png" (https://wmprod.oss-cn-shanghai.aliyuncs.com/images/20250105/5c825879ccb504bafeb82fa116a3d805.png) 截图逻辑: "image.png" (https://wmprod.oss-cn-shanghai.aliyuncs.com/images/20250105/d6b963aaa2d3f252b36c12957ce59289.png) 请问大佬们有遇到过吗?麻烦指点下 执行"locate libgobject-2.0.so": "image.png" (https://wmprod.oss-cn-shanghai.aliyuncs.com/images/20250105/d126a72eb4f0924a71ceba52dc7f7c33.png) 这个是否说明已安装。如果没有安装,请问如何下载"libglib",因为我用"yum"下载不下来 "image.png" (https://wmprod.oss-cn-shanghai.aliyuncs.com/images/20250105/31074086f2e58dd4d4eac061e495f93c.png) 如果说明已安装,我在Dockerfile加入了命令: "image.png" (https://wmprod.oss-cn-shanghai.aliyuncs.com/images/20250105/a338db375806a1576651bddb7698e409.png) 但是我重新打包镜像运行,结果依然是报错,报错信息没有变 你把它放到 node 前看看。比如 RUN LD_LIBRARY_PATH=/usr/lib64:$LD_LIBRARY_PATH node node_modules/.... 尝试后的结果: "image.png" (https://wmprod.oss-cn-shanghai.aliyuncs.com/images/20250105/f849cf106103d9599287ea127505647a.png)
[2024.08.12 新增]报找不到各种依赖的问题,在/lib里都能找到(此处比较奇怪,我在有网的机器都是在lib64里的,不知道为啥没网的这些都在lib里),就是一运行ldd 就not found。 尝试了网上说的修改ld.so.conf 增加了/lib 的路径也还是not found "image.png" (https://wmprod.oss-cn-shanghai.aliyuncs.com/c/user/20240917/a7850d0e44c7e47406c89eb7fe47bf2f.png) *** 如题,用的yumdownloader --resolve 下载所有需要的安装包,在无网机器里用yum localinstall *.rpm后,执行./chrome 提示如下: «./chrome: error while loading shared libraries: libatk-bridge-2.0.so.0: cannot open shared object file: No such file or directory» 遂在有网的机器上执行yumdownloader ,结果居然没有,百度了下网下说安装at-spi2-atk,可是我安装完执行./chrome 还是报那个错。 yumdownloader 下载不到libatk-bridge "image.png" (https://wmprod.oss-cn-shanghai.aliyuncs.com/c/user/20240917/d081c6f89ea35acb0a5b27615c5626dc.png) 网图 "image.png" (https://wmprod.oss-cn-shanghai.aliyuncs.com/c/user/20240917/71b266898dea7781abe82f0b3b8b1ea3.png) 根据网上说的安装at-spi2-atk "image.png" (https://wmprod.oss-cn-shanghai.aliyuncs.com/c/user/20240917/1389b81f09ad97c8abf7dad14b3211f6.png)
如题,前两天测试的时候还是正常的,今天突然发现生成的pdf多了空白页,有没有人遇到过啊? "image.png" (https://wmprod.oss-cn-shanghai.aliyuncs.com/images/20241119/ab05924c791f2727d70445b352b5f898.png)
/Applications/Google Chrome.app/Contents/MacOS/Google Chrome', '--user-data-dir=/Users/interface/PycharmProjects/DjangoForWelock/user-data-dir/Profile', '--remote-debugging-port=9223 这代码是重新打开一个浏览器,而不是复用我现有的 const puppeteer = require('puppeteer'); async function a() { const browser = await puppeteer.launch({ headless: false, devtools: true, args: ['--remote-debugging-port=9223', '--remote-debugging-address=localhost', '--no-sandbox'], }); const page = await browser.newPage(); await page.goto('https://youtube.com/', {waitUntil: 'networkidle0'}); } a().then(r => console.log("sadf"))
puppeteer如何设置请求到页面源码后,该标签的页面不继续执行,而是执行下个任务? puppeteer如何设置请求到页面源码后,该标签的页面不继续执行,而是执行下个任务?
用puppeteer生成网页的pdf,网页排版用的div(float)>table ,网页看是正常的,生成pdf就多了一点空隙 网页正常显示 "image.png" (https://wmlx-new-image.oss-cn-shanghai.aliyuncs.com/images/20241030/356d671c263fde060e5d7533e5e08120.png) pdf显示多了空白间隙 "image.png" (https://wmlx-new-image.oss-cn-shanghai.aliyuncs.com/images/20241030/81ec8788a0a70781d026351f1128cff7.png) finderror.html Document * { margin: 0; padding: 0; } /* A4-纵向 */ .wrapper-v { /* 边距为0 */ width: 794.12px; /* 边距为5cm,对应需减去边距 */ width: 756.305px; /* min-height: 1090px; */ /* width: 1075px; height: 1568px; */ } /* A4-横向 */ .wrapper-h { /* width: 1090px; min-height: 794px; */ /* 边距为0 */ width: 1123.11px; /* 边距为0.5cm,对应需减去左右边距 */ width: 1085.295px; /* width: 1569px; height: 1075px; */ } .wrapper { /* display: flex; flex-direction: column; align-items: center; clear: both; */ /* 使用样式控制分页 */ /* margin-left: 25px; */ /* 影响puppeteer分页 */ /* display: flex; flex-direction: row; align-items: center; flex-wrap: wrap; */ box-sizing: border-box; /* 控制在打印预览中的左边距,设置为0则贴边,上边距在page里设置 */ /* padding: 15px 15px; */ /* padding-top: 15px; */ /* padding-left: 15px; */ padding: 1px; /* clear: both; */ overflow: hidden; /* 使用样式控制分页 */ } .w-h, .w-v { float: left; /* page-break-inside: avoid; */ } /* 纵向-外框 */ .w-v { /* width: 266px; height: 361px; */ width: 272.27px; height: 369.07px; /* 1cm = 39.862px */ /* width: 287.006px; height: 389.053px; */ /* 1cm=41.192px */ /* width: 298.742px; height: 404.962px; */ } /* 横向-外框 */ .w-h { /* width: 382px; height: 235px; */ width: 391.01px; height: 240.13px; /* width: 392px; height: 241px; */ } .wrapper-v .w-v:nth-of-type(4n) { /* margin-bottom: 180px; */ page-break-after: always; } .wrapper-h .w-v:nth-of-type(6n) { /* margin-bottom: 120px; */ page-break-after: always; } .w-v table { width: 100%; height: 100%; border-collapse: collapse; border: 1px solid black; page-break-inside: avoid; } .w-v table tr:first-of-type { font-weight: bolder; font-family: "仿宋"; height: 32px; line-height: 32px; text-align: center; font-size: 15px; letter-spacing: 8px; } .w-v table tr:nth-of-type(2) { height: 208px; text-align: center; } .w-v table tr:nth-of-type(3), .w-v table tr:nth-of-type(4), .w-v table tr:nth-of-type(5) { height: 28px; } .w-v table tr:nth-of-type(6) { height: 36px; text-align: center; font-family: fangsong; font-weight: bolder; } .w-v table tr:nth-of-type(2) td .w-v table tr:nth-of-type(3) td, .w-v table tr:nth-of-type(4) td, .w-v table tr:nth-of-type(5) td { font-size: 16px; text-align: center; } .w-v table tr:nth-of-type(3) td, .w-v table tr:nth-of-type(4) td, .w-v table tr:nth-of-type(5) td { font-size: 14px; line-height: 16px; text-align: center; } .w-v table tr:nth-of-type(2) td { /* width: 260px; */ line-height: 30px; font-family: "Microsoft YaHei"; font-size: 26px; /* 使用puppeteer时,竖向文字不起效果 */ /* writing-mode: vertical-lr; */ /* letter-spacing: 5px; */ } /* 解决使用puppeteer时,竖向文字不起效果 */ .w-v table tr:nth-of-type(2) td span { display: inline-block; width: 25px; line-height: 32px; } /* .w-v table tr:nth-of-type(3) td, .w-v table tr:nth-of-type(4) td{ vertical-align: middle; } */ .w-v table tr:nth-of-type(5) td { font-size: 15px; } @media print { body { margin: 0; padding: 0; } @page { /* margin: 1cm -0.25cm; */ /* margin: 0cm; */ /* 此处设置size 影响pdf横向纸张生成 */ /* size: a4; */ margin: 0.5cm; scale: 1; /* 设置打印上边距 */ /* margin-top: 25px; */ } body { /* 页面背景色 通过js控制 */ /* Chrome、Safari 等 webkit 浏览器内核 */ -webkit-print-color-adjust: exact; /* 火狐 */ print-color-adjust: exact; color-adjust: exact; } .wrapper { margin: 0; padding: 0; } } createPdf.js const puppeteer = require("puppeteer"); const path = require("path"); (async function () { const browser = await puppeteer.launch({ headless: true, }); const page = await browser.newPage(); await page.goto( "file:///G:/finderror.html", { timeout: 0, } ); await page.waitFor(5000); await page.pdf({ scale: 1, printBackground: true, /* ————————————更改纸张方向及颜色———————————————— */ // 设置纸张是否为横向 landscape: true, /* ————————————更改纸张方向及颜色———————————————— */ format: "A4", path: path.join(__dirname, "./测试.pdf"), }); await browser.close(); })(); 尝试: * 与collapse无关 * 与添加page-break-after:always无关 希望获得的结果: 生成pdf与网页预览一致