My current project involves using Puppeteer for web scraping on my website. I encountered a strange issue where the await page.content()
works fine when I console log the content, but turns out to be null when passed as an argument to another JavaScript function. This is perplexing because I can clearly see the content in the browser itself. It's even more baffling considering that I've successfully implemented the same logic for other URLs on the site without any problems. Only this particular instance seems to be causing trouble with await page.content()
returning null. While it's possible to pass await page.content()
directly as an argument, it's not ideal due to potential high server load based on specific conditions.
func1(){
let a = await page.content()
console.log(a) // content is displayed correctly
}
func2(){
func3(page);
}
func3(page){
let c = await page.content()
console.log(c);
//The output is empty
}