index.js
(async () => {
await global.initialize();
let lineCount = await global.count();
let globalData = [];
let childNum = null;
let lineBaseSelector = null;
for(let i = 1; i < lineCount; i++)
{
childNum = i + 1;
lineBaseSelector = '#alx-content > div.row-fluid.TopSites.AlexaTool.padding20 > section.page-product-content.summary.padding20 > span > span > div > div > div > div:nth-child(' + `${childNum}` + ')';
let details = await global.getDetails(lineBaseSelector);
globalData.push(details);
}
global.js
getDetails: async (lineBaseSelector) => {
let url = await page.url();
await page.waitForSelector(lineBaseSelector);
let details = await page.evaluate(() => {
return {
rank: document.querySelector('div[class="td"]').innerText,
name: document.querySelector('p > a').innerText,
url: document.querySelector('p > a').getAttribute('href')
}
});
return details;
},
LineBaseSelector changes dynamically and I want to get every data in which belongs to these selectors as a list. But the data list which I get consists of just the first data. There are 50 datas but I can get just the first one 50 times. I also tried changing the querySelector as "rank: document.querySelector(lineBaseSelector + 'div[class="td"]').innerText," but I had an error called Uncaught Error: Evaluation failed: ReferenceError: lineBaseSelector is not defined. Please help me to solve this. Thank you so much.