Created
November 23, 2022 16:32
-
-
Save alanhr/83914cb6714f874863f2a03f784afd4c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { createWriteStream } from 'fs' | |
import { resolve } from 'path' | |
import fetch from 'node-fetch' | |
import playwright from 'playwright' | |
;(async () => { | |
const browser = await playwright['chromium'].launch({ | |
}) | |
const context = await browser.newContext({ acceptDownloads: true }) | |
const imagesPage = await context.newPage() | |
await loginPage.waitForNavigation() | |
await imagesPage.goto( | |
'https://url' | |
) | |
const images = imagesPage.locator('img') | |
const imageCounts = await images.count() | |
for (let index = 0; index < imageCounts; index++) { | |
const image = await images.nth(index) | |
const imageSrc = await image.getAttribute('src') | |
if (!imageSrc) continue | |
const { body } = await fetch(imageSrc) | |
await body.pipe( | |
createWriteStream(resolve(`./path.png`)) | |
) | |
} | |
await browser.close() | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment