I was able to increment my nth-child(n)
by moving my selector to XPath
. Certainly not optimal, but it works.
the XPath
for my scraping code looks like:
for (b=1; b<5; b++) {
await page.waitForXPath('//*[contains(concat( " ", @class, " " ), concat( " ", "table__tr", " " )) and (((count(preceding-sibling::*) + 1) = '+b+') and parent::*)]//*[contains(concat( " ", @class, " " ), concat( " ", "table__td", " " ))]');
let elhandle = await page.$x('//*[contains(concat( " ", @class, " " ), concat( " ", "table__tr", " " )) and (((count(preceding-sibling::*) + 1) = '+b+') and parent::*)]//*[contains(concat( " ", @class, " " ), concat( " ", "table__td", " " ))]');
let game = await page.evaluate(el => el.textContent, elhandle[0]);
let ddd = await page.evaluate(el => el.textContent, elhandle[1]);
oo = oo + '{","game":" ' + game +' ","date":" ' + ddd + ' "}, \n'
} // b
notice that XPath
allows the b
variable to be incremented.
preprocessor
likesass
for example – Borszcz