Untitled

mail@pastecode.io avatar
unknown
javascript
a year ago
1.4 kB
1
Indexable
Never
//Puppeteer library


const pt= require('puppeteer')
var cron = require('node-cron');



console.log("Running")




async function getText(){

    

    


    currentDate = new Date()
    let time = currentDate.getHours() + ":" + currentDate.getMinutes() + ":" + currentDate.getSeconds();
   //launch browser in headless mode
   const browser = await pt.launch({ headless: false });
   console.log("Started getText function")
   //browser new page
   const page = await browser.newPage()
   //launch URL
   await page.goto('example.com')
   //identify element
    const f = await page.$("[class = 'font-1rem']")
    //const ada = await page.$("[class = 'catelog-time ends-time']")
   //obtain text

  
    let text = await (await f.getProperty('innerHTML')).jsonValue()
    
    
    /*if(parseInt(timer)) {
     console.log("Timer not finished.")
    }
    else {
     console.log("Timer is done.");
     //process.exit();
    }*/


   console.log(text)

  if(text != "Current Bid : 6.25") {
        browser.close();
        console.log(`Changed recorded during ${time}. ${text}`);
        
        return msg();
    } else {
        browser.close()
        console.log(`No change at ${time}`)

    }




    
}



cron.schedule('59 * * * * * *', () => {
  console.log('Running again in 59 seconds');
  getText()
})