@fbi_agent26

Puppeter node js как установить регистр?

Суть вопроса такая - как установить одинаковый регистр текста ?
Вот кусок кода, как видно у меня поиск идет через indexOf а он зависит от регистра.
Менять регистр через .toUpperCase() я умею, но я не знаю как прописать его так, чтобы он менял регистр в браузере puppeter.
Пример кода.
const page = await browser.newPage();

try
{
await page.goto(htmlent.decode(decodeURIComponent(products[i].search_link)) + result[0].model);

await delay(4000);


const html = await page.content();
const $ = cheerio.load(html);


var links = [];

$('span').each(function()
{
if($(this).text().indexOf(result[0].model) > -1)
{
if($(this).parent().attr('href') != undefined)
{
links.push($(this).parent().attr('href'));
console.log($(this).parent().attr('href'));
}

}


});

$('div').each(function()
{
if($(this).text().indexOf(result[0].model) > -1)
{
if($(this).parent().attr('href') != undefined)
{
links.push($(this).parent().attr('href'));
console.log($(this).parent().attr('href'));
}

}


});

$('strong').each(function()
{
if($(this).text().indexOf(result[0].model) > -1)
{
if($(this).parent().attr('href') != undefined)
{
links.push($(this).parent().attr('href'));
console.log($(this).parent().attr('href'));
}

}


});

$('a').each(function()
{
if($(this).text().indexOf(result[0].model) > -1)
{
links.push($(this).attr('href'));
console.log($(this).attr('href'));
}


});

$('a').each(function()
{

if($(this).attr('title') != undefined)
{
if($(this).attr('title').indexOf(result[0].model) > -1)
{
links.push($(this).attr('href'));
console.log($(this).attr('href'));
}
}


});

var title = 0;
if(links.length > 0)
{

if(links[0].indexOf('http://') < 0 && links[0].indexOf('https://'))
{
links[0] = getProtocol(decodeURIComponent(products[i].search_link))+'//'+getHostname(decodeURIComponent(products[i].search_link))+'/'+links[0];
//console.log(links[0]);
}

await page.goto(links[0].split("?q")[0]);
const html = await page.content();
const $ = cheerio.load(html);
await delay(2000);
$('title').each(function()
{
if($(this).text().indexOf(result[0].model) > -1)
{
title = 1;

}

});
=======
это не весь код, но тут и парсер cheerio виден и сам puppeter , обрезано то что к делу не отностится
  • Вопрос задан
  • 41 просмотр
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы