You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When opening a cloudflare protected page I get this:
Code Snippet
constpuppeteer=require("puppeteer-extra");constStealthPlugin=require("puppeteer-extra-plugin-stealth");constpath=require("path");constfs=require("fs");constwinston=require("winston");constDailyRotateFile=require("winston-daily-rotate-file");constmysql=require("mysql");constutil=require("util");// Apply the stealth plugin to avoid being detected as a botconstpuppeteerStealth=StealthPlugin();puppeteerStealth.enabledEvasions.delete('user-agent-override');puppeteer.use(puppeteerStealth);require("dotenv").config({path: path.resolve(__dirname,"../../.env")});require("dotenv").config({path: path.resolve(__dirname,"../.env")});constconnection=mysql.createConnection({host: process.env.DB_HOST,user: process.env.DB_USERNAME,password: process.env.DB_PASSWORD,database: process.env.DB_DATABASE,port: process.env.DB_PORT});connection.connect();constappEnvironment=process.env.APP_ENV;constimgDirectory=path.join(__dirname,"_img");if(!fs.existsSync(imgDirectory)){fs.mkdirSync(imgDirectory,{recursive: true});}constlogDirectory=path.join(__dirname,"_logs");if(!fs.existsSync(logDirectory)){fs.mkdirSync(logDirectory,{recursive: true});}constlogger=winston.createLogger({level: "info",format: winston.format.combine(winston.format.label({label: "quietlight"}),winston.format.timestamp(),winston.format.printf(({ level, message, label, timestamp })=>{return`${timestamp} [${label}] ${level}: ${message}`;})),transports: [newwinston.transports.Console(),newDailyRotateFile({filename: path.join(logDirectory,"quietlight_%DATE%.log"),datePattern: "YYYY-MM-DD",zippedArchive: true,maxSize: "20m",maxFiles: "7d",}),],});asyncfunctioncaptureScreenshot(page,tag){// Generate a dynamic filename based on the current timeconsttimestamp=newDate().toISOString().replace(/[^0-9]/g,"");constfilename=`screenshot_${tag}_${timestamp}.png`;constscreenshotPath=path.join(imgDirectory,filename);// Try to capture and save the screenshottry{awaitpage.screenshot({path: screenshotPath,fullPage: true});logger.info(`Screenshot of the page has been captured and saved to ${screenshotPath}.`);}catch(error){logger.error("An error occurred while capturing a screenshot of the page:",error);}}// This function calculates the duration and logs itfunctionlogDuration(startTime){constendTime=newDate();constduration=(endTime-startTime)/1000;// Duration in secondslogger.info(`Script execution time: ${duration} seconds`);}conststartTime=newDate();logger.info(`############# Starting Quietlight Scrapper #############`);logger.info(`Running on Node.js ${process.version}`);logger.info(`App Environment: ${appEnvironment}`);(async()=>{constbrowser=awaitpuppeteer.launch({// headless: appEnvironment === "local" ? false : "new",headless: true,// THIS, if you want to see the browserargs: ['--no-sandbox','--disable-setuid-sandbox','--disable-dev-shm-usage','--disable-accelerated-2d-canvas','--disable-gpu','--lang=en-US,en',// Set language explicitly],});try{// const [page] = await browser.pages();constpage=(awaitbrowser.pages())[0];// <-- bypasses Cloudflareawaitpage.setViewport({width: 1366,height: 768});awaitpage.setUserAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.82 Safari/537.36");awaitpage.setExtraHTTPHeaders({'Accept-Language': 'en-US,en;q=0.9'});page.setDefaultNavigationTimeout(0);awaitpage.goto("https://quietlight.com/",{waitUntil: 'networkidle2'});captureScreenshot(page,"quietlightPage")awaitpage.waitForSelector("img");awaitpage.waitForTimeout(10000);}catch(error){captureScreenshot(page,"errorInMainLoop")logger.error("An error occurred during the script execution:",error);}finally{if(browser){awaitbrowser.close();}connection.end();logDuration(startTime);logger.info(`############# End quietlight Scrapper #############`);process.exit();}})();
Describe the bug
When opening a cloudflare protected page I get this:
Code Snippet
Versions
This is my package.json:
The text was updated successfully, but these errors were encountered: