I'm trying to get some links from a website with the help of puppeteer.
async function getLinks(){
const first = 'first';
const last = 'last';
const browser = await browserControl.startBrowser();
const page = await browser.newPage();
await page.goto(url_baseStats);
// await page.waitForNavigation();
let links = await page.evaluate((first, last) => {
try {
let links = Array.from(document.querySelectorAll('a'), a => a.getAttribute('href'));
links = links.slice(links.indexOf(first), links.indexOf(last));
return links;
} catch(err) {
throw err;
}
});
console.log("links:", links);
return links;
}
I have 2 question's:
When I'm running the debugger he gets to the "await page.evaluate((..."-point and then jumps straight up to the "console.log(...". Why he doesn't wait?
Why I need to pass the variables first & last as parameters to the evaluation-function? I defined them above, they should be in the scope of the evaluation function?!?
Thanks in advance ;_)