I would like to collect some info from a page. First I check with Chrome inspect and console how to find the right value and it was everything ok. Then I paste the code into puppeteer, cheerio environment and some reason I can not collect the right data.
This is the part what is working in chrome:
const modellek = $('[columntype="model"] > section > ul > li').map(function() {
return ($(this).text())});
console.log(modellek)
["txt1","txt2","txt3","txt4"...]
The JS script is the following:
const puppeteer = require("puppeteer");
const cheerio = require("cheerio");
async function scrapHome(url){
try{
const browser = await puppeteer.launch({headless: false});
const page = await browser.newPage();
await page.setViewport({width: 1366, height: 768});
await page.setUserAgent('Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108');
const html = await page.evaluate(() => document.body.innerHTML);
const $ = await cheerio.load(html);
await page.goto(url);
const models= $('[columntype="model"] > section > ul > li').map(function() {
return ($(this).text().get())});
console.log(models)
} catch (err) {
console.error(err);
};
};
scrapHome("https://example.com/");
But the result is an empty array : [].
I also tried the waitForSelector but in that case there is no any response.
page
.waitForSelector('[columntype="model"]')
.then(() => $('[columntype="model"] > section > ul > li').map(function() {
console.log ($(this).text())
}));
Any idea how to get the requested info?