I am trying to scrape any web page passed as into the scrape function, but no matter the timeout set at page.goto(), I keep getting a timeout error, if set to 0, the app just keeps waiting.
const express = require('express');
const cors = require('cors');
const MYPORT = process.env.PORT || 4001;
const app = express();
const puppeteer = require('puppeteer');
app.use(express.json());
app.use(cors());
const scrape = async (url) => {
var body;
try {
const browser = await puppeteer.launch({
headless: true,
args: ['--no-sandbox'],
timeout: 0
});
console.log('Browser launched');
const page = await browser.newPage();
console.log('Page opened');
await page.goto(url, { waitUntil: 'load', timeout: 3 * 60000 });
await page.waitForSelector('body', {waitUntil: 'load'})
console.log('Link opened');
await page.waitForNavigation({waitUntil: 'networkidle2', timeout: 3 * 60000});
page.$eval('html', bdy => {
console.log(bdy);
body = bdy.innerHTML;
});
browser.close();
return body;
} catch (err) {
console.log(err);
}
};
scrape('http://google.com');
Please, what am I doing wrong?
I am using Ubuntu 18.04 on WSL (Windows Subsystem for Linux)