When I Run my node API in headless: false
mode then it could open a browser instance and I can get the data. but when I use headless: true
then it shows access denied and doesn't scrape data. My code below.
(async () => {
const browser = await puppeteer.launch({
headless: false
});
const page = await browser.pages();
await page[0].goto(url);
const my = await page[0].evaluate(() => {
let title = document.getElementsByClassName('p-name')[0].innerHTML.trim();
return title;
});
console.log(my);
res.status(200).json(my);
await browser.close();})();
I search for a solution and found this one (Puppeteer opens an empty tab in non-headless mode). This unable to solve my problem completely. This helped me to close the additional browsers that open. Thanks in advance.
This Url I wanna scrape is : https://www.macys.com/shop/product/nike-big-boys-sportswear-t-shirt?ID=11252136&CategoryID=6086&swatchColor=Dark%20Gray%20Heather