将JS转换为cheerio的问题

问题描述

我正在使用cheerio 进行网页抓取。我可以在浏览器中使用下面的代码获取我需要的值。我遇到的问题是将其转换为cheerio,因为我需要使用请求进行解析。我个人觉得cheerio 文档有点令人困惑,我尝试过的方法没有奏效。如果有人可以帮助我将其转换为cheerio,将不胜感激。

let lol = JSON.parse(document.querySelector('#maincontent > script:nth-child(5)').innerHTML.split('{"variants":')[1].split(`};`)[0])
lol.forEach((res)=>{
if(res.width == 'D'){
if(res.style == 'M1080W11'){
console.log(res)
}
}
})

解决方法

你会替换这个:

 //do this for all conditions
 if (((BaseItem) object).getName().equals("Tomorrowland Winners")) {
      displaySelectedScreen("TOMORROWLAND WINNERS");
 }

与:

document.querySelector('#maincontent > script:nth-child(5)').innerHTML