Just started using Puppeteer. Trying to parse a page but the evaluate method won't work somehow.
var Browser
var Page
var Result
puppeteer.launch()
.then(function (browser) {
console.log('Browser Created\nCreating Blank Page')
Browser = browser
return Browser.newPage()
})
.then(function (page) {
console.log('Page Created\nVisiting URL')
Page = page
return Page.goto(URL)
})
.then(function (resp) {
console.log('Website Loaded')
return Page.evaluate(function () {
// Completely Sync Stuff
console.log('Evaluating Selectors')
var myElems = document.getElementsByClassName('challenge-type light')
Result = myElems
})
})
.then(function (val) {
console.log(Result)
console.log('Done! Exiting')
Browser.close()
process.exit()
})
.catch(function (err) {
Browser.close()
console.log(err)
process.exit(1)
})
Output :
Browser Created
Creating Blank Page
Page Created
Visiting URL
Website Loaded
undefined
Done! Exiting
What could possibly be the error? Would prefer a solution without async/await.
EDIT: "Evaluating Selectors" is not logged to the console as well, so the code never reaches there, is my concern.