1 | initial version |
The process for downloading images with authentication query strings in the image URL when using Puppeteer as a tool can be achieved through the following steps:
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
// your code here
await browser.close();
})();
await page.goto('https://example.com');
<img>
tag with a src
attribute, you can use the following code to extract the URL:const imageURL = await page.$eval('img', (img) => img.src);
?token=123456789
, you would add it to the URL using the following code:const authenticatedURL = imageURL + '?token=123456789';
request
library to download the image:const request = require('request');
const fs = require('fs');
request(authenticatedURL)
.pipe(fs.createWriteStream('image.jpg'));
This code downloads the image and saves it as image.jpg
in the current directory.