Skip to content

Instantly share code, notes, and snippets.

@techwiz37
Created October 7, 2023 04:38
Show Gist options
  • Select an option

  • Save techwiz37/e3d755075839cb5c1a1da82b1662f65a to your computer and use it in GitHub Desktop.

Select an option

Save techwiz37/e3d755075839cb5c1a1da82b1662f65a to your computer and use it in GitHub Desktop.
Ai image generator
/*
2023 © Amirul Dev
recode sertakan sumber biar semangat update :)
custom request? silahkan donasi
wa: 085157489446
*/
import playwr from "playwright";
const browser = await playwr.chromium.launch({
headless: true,
acceptDownloads: true, // permission download
downloadsPath: "@amiruldev", // path download
});
const context = await browser.newContext({
permissions: ["clipboard-read"],
});
const page = await context.newPage();
// ubah ukuran
await page.setViewportSize({ width: 501, height: 700 });
await page.goto("https://freeimagegenerator.com/");
// input form
await page.type(
"input#inputAIPrompt.inputFindAIImages",
"spongebob with bkue car"
);
// klik generate
await page.click("button#buttonCreateAIImages.buttonFindAIImages");
// menunggu element
await page.waitForSelector(".aiImageContainerDiv");
// get element result
const resEl = await page.$(".aiImageContainerDiv");
// get url img
const bgImg = await resEl.getAttribute("style");
const url = bgImg.match(/url\('(.+)'\)/)[1];
console.log(url);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment