pyppeteer无头模式无法正常渲染SSR页面 背景显示空白问题求助
问题描述
- 使用pyppeteer爬取页面https://loja.meo.pt/Equipamentos/gaming/Sony/PS5-Digital-Comando-DS-Plus-Card-365-dias?cor=Branco&modo-compra=PromptPayment时,截图功能运行正常,可正常显示Cookie同意弹窗,但页面背景为纯白色
- 执行JS代码接受Cookie后再次截图,弹窗消失,即便重载页面,背景仍为空白
- 相同场景在Node.js版本的puppeteer(基于开源项目streetmerchant实现)中可正常运行,暂未排查到问题根因,初步怀疑是页面的React应用未正常启动
相关测试代码如下:
url = "https://loja.meo.pt/Equipamentos/gaming/Sony/PS5-Digital-Comando-DS-Plus-Card-365-dias?cor=Branco&modo-compra=PromptPayment" browser = await launch( ignoreHTTPSErrors=True, headless=True, executablePath=os.getenv('CHROME_PATH'), args=[ '--no-sandbox', '--disable-setuid-sandbox', '--disable-dev-shm-usage', '--headless', '--disable-gpu', '--ignore-certificate-errors' ] ) page = await browser.newPage() await page.setViewport({'width': 1920, 'height': 1280}) await page.goto(url, {'waitUntil': 'networkidle0'}) await page.screenshot({'path': 'screenshot.png'})
解决方案
脚本本身运行逻辑无异常,问题根源为Docker和卷挂载配置异常:多个运行相同脚本的实例读取了旧的截图和旧版本脚本,清理所有相关实例后重启脚本即可恢复正常。
内容的提问来源于stack exchange,提问作者Luis Lopes
相关产品推荐
相关产品推荐

