I've been trying to iterate over a list of divs, nearly identical besides the data displayed in them, that are under a certain section of the dom, <aside>
, in order to grab the innerText from each one of them. The result functions properly when hardcoding an nth-child
number, however, trying to iterate it in a for loop produces the error: Error: Evaluation failed: ReferenceError: i is not defined at __puppeteer_evaluation_script__:1:130
. Confused as to what's going on here.
for (let i = 1; i < 9; i++) {
let info = await page.evaluate(
() => [...document.querySelectorAll(`#root > main > div.sc-jcVebW.eVwwrC > div.sc-bZSQDF.dgraCx > div > aside > div:nth-child(${i}) > div.sc-dlfnbm.ujoHC > div.sc-hKgILt.beOqPu > div > h2`)].map(elem => elem.innerText)
);
console.log(info)
}