import puppeteer from "puppeteer";
import axios from "axios";
import fs from "fs";
const botAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36";
const crawlerBot = async () => {
try {
const browser = await puppeteer.launch({
headless: false,
args: ["--window-size=1920,1080"],
});
const page = await browser.newPage();
await page.setUserAgent(botAgent);
await page.goto("https://unsplash.com");
await page.waitFor(2000);
const result = await page.evaluate(() => {
const imageArray = [];
const image = document.querySelectorAll(".ripi6 img.YVj9w");
if (image.length) {
image.forEach((e) => {
imageArray.push(e);
});
}
return imageArray;
});
console.log(result);
await page.close();
await browser.close();
} catch (err) {
console.error(err);
}
}
crawlerBot();
cheerio처럼 html 해석하는 걸로 착각했네요 감사합니다.