【问题标题】:How can I handle puppeteer to save pdf from a print dialog?如何处理 puppeteer 从打印对话框中保存 pdf?
【发布时间】:2017-12-31 05:37:40
【问题描述】:

我有一个打印按钮,单击它会发送一些请求并打开打印对话框。现在这不是直接来自 URL,也不容易解码。

打印对话框示例

有没有办法可以使用 puppeteer 将此文档保存为 pdf?

现有代码:

const puppeteer = require('puppeteer');

(async () => {
  const browser = await puppeteer.launch();
  const page = await browser.newPage();
  await page.setViewport({width: 1440, height: 2000});
  await page.goto(`https://www.southwest.com/air/check-in/review.html?confirmationNumber=${process.argv[2]}&passengerFirstName=${process.argv[3]}&passengerLastName=${process.argv[4]}`, {
    waitUntil: 'networkidle2'
  });
  [ confirmationNumber, checkinButtonText ] = [ await page.$eval('.confirmation-number--code', el => el.innerHTML), await page.$eval('.actionable_primary.actionable_large-button', el => el.innerHTML) ]
  console.log(checkinButtonText);
  console.log(confirmationNumber);
  await page.click('.actionable_primary.actionable_large-button');
  // The below line makes a click on the button
  await page.click('.air-check-in-boarding-pass-options .boarding-pass-options--button-email, .air-check-in-boarding-pass-options .boarding-pass-options--button-print, .air-check-in-boarding-pass-options .boarding-pass-options--button-text');
  await browser.close();

})();

【问题讨论】:

  • 请分享您的代码和结果示例。
  • 请检查更新后的代码。除非您以前有西南航空公司的机票,否则我认为这对您没有帮助。

标签: selenium automation headless-browser puppeteer google-chrome-headless


【解决方案1】:

here 有一个 .pdf api。

示例用法:

await page.pdf({path: 'myTicket.pdf'});

【讨论】:

    猜你喜欢
    • 2012-07-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多