Skip to content

Instantly share code, notes, and snippets.

@alanhr
Created November 23, 2022 16:32
Show Gist options
  • Save alanhr/83914cb6714f874863f2a03f784afd4c to your computer and use it in GitHub Desktop.
Save alanhr/83914cb6714f874863f2a03f784afd4c to your computer and use it in GitHub Desktop.
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