Back to articles
How to Monitor Competitor Websites for Changes Automatically

How to Monitor Competitor Websites for Changes Automatically

via Dev.to TutorialАлексей Спинов

Want to know when a competitor changes their pricing, adds a product, or updates their website? Here is how to set up automatic monitoring. The Architecture Scraper → Hash/Diff → Database → Alert (email/Slack) Simple Change Detector const crypto = require ( " crypto " ); const fs = require ( " fs " ); async function checkForChanges ( url , name ) { const res = await fetch ( url , { headers : { " User-Agent " : " Monitor/1.0 " } }); const html = await res . text (); const hash = crypto . createHash ( " md5 " ). update ( html ). digest ( " hex " ); const file = `hashes/ ${ name } .txt` ; const prevHash = fs . existsSync ( file ) ? fs . readFileSync ( file , " utf8 " ) : "" ; if ( hash !== prevHash ) { console . log ( `CHANGED: ${ name } ` ); fs . writeFileSync ( file , hash ); // Send alert here return true ; } return false ; } Monitor Specific Elements const cheerio = require ( " cheerio " ); async function monitorPrice ( url , selector ) { const res = await fetch ( url ); const $ = che

Continue reading on Dev.to Tutorial

Opens in a new tab

Read Full Article
3 views

Related Articles