-
Notifications
You must be signed in to change notification settings - Fork 0
/
getimg.js
32 lines (22 loc) · 940 Bytes
/
getimg.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
const puppeteer = require('puppeteer');
const fs = require('fs');
if (process.argv.length !== 4) {
console.log('Usage: node app.js <domain> <output_file>');
process.exit(1);
}
const domain = process.argv[2];
const outputFile = process.argv[3];
console.log(`Fetching Domain : ${domain}`);
console.log(`Output File: ${outputFile}`);
(async () => {
// Launch a headless browser
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto("https://" + domain); // Replace with the URL of the webpage you want to scrape
await page.waitForSelector('#turtlecanvas'); // Replace with the selector for the canvas element
const canvas = await page.$('#turtlecanvas'); // Replace with the correct canvas selector
const imageData = await canvas.screenshot();
await browser.close();
fs.writeFileSync(outputFile, imageData);
console.log('Image saved as scraped_image.png');
})();