【发布时间】: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