I'm new to all this so any suggestions about resources to learn from would also be appreciated! So as I mentioned I'm using puppeteer, js and node. When I try to run the blow code I get "placeholder is not defined" but if I just put in the number 4 I get the link I'm looking for which in this example is https://stackoverflow.com/users.
I'm really unsure why this happened, one of the closest examples of this error suggested that it loads the variable and runs the code before the page loads, but I don't think that's the issue.
Essentially I want to get a list of all the links on a page or more specifically in lists and access them, I'd bet this isn't the best way to navigate a site or links but have been trouble finding some resources that are useful.
const puppeteer = require('puppeteer');
const fs = require('fs');
async function MyFunction(scrapelink){
const browser = await puppeteer.launch({headless:false});
const page = await browser.newPage();
await page.goto(scrapelink, {waitUntil: "networkidle2"});
const placeholder = 4;
const fourthLink = await page.evaluate(() => document.links[placeholder].href);
//changing placeholder with just 4 works.
console.log(fourthLink);
browser.close();
}
MyFunction("https://stackoverflow.com/");