Home > Software design >  Scraping <li> usingg puppeter/ cheerio
Scraping <li> usingg puppeter/ cheerio

Time:09-11

I've tried using a loop with a selector to scrape the <li>, but it doesn't work.

i want to get "Program Studi Perencanaan Wilayah Dan Kota" this value and the other value

Node Cheerio code:

$('div#panel-penggiat-collapse-0 > div > div:nth-of-type(2) > div:nth-of-type(2) > span > span > span > ul > li').each((i, el) => {
  console.log($(el).text())
})

HTML:

<ul >
  <li  title="Program Studi Perencanaan Wilayah Dan Kota"><span  role="presentation">×</span>Program Studi Perencanaan Wilayah Dan Kota</li>
  <li  title="Program Studi Matematika"><span  role="presentation">×</span>Program Studi Matematika</li>
  <li  title="Program Studi Fisika"><span  role="presentation">×</span>Program Studi Fisika</li>
  <li  title="Program Studi Statistika"><span  role="presentation">×</span>Program Studi Statistika</li>
  <li  title="Program Studi Sistem Informasi"><span  role="presentation">×</span>Program Studi Sistem Informasi</li>
  <li  title="Program Studi Desain Komunikasi Visual"><span  role="presentation">×</span>Program Studi Desain Komunikasi Visual</li>
  <li  title="Program Studi Teknik Komputer"><span  role="presentation">×</span>Program Studi Teknik Komputer</li>
  <li ><input  type="search" tabindex="-1" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" role="textbox" placeholder="" style="width: 0.75em;"></li>
</ul>

CodePudding user response:

You probably have issues with your selector. There is nothing wrong in your code.

I have put your code here:

https://scrapeninja.net/cheerio-sandbox?slug=8669ef61805c9903e3845656681d8d02de44aabc

and console.log works properly for simpler selector.

CodePudding user response:

It's hard to guess but possibly:

$('ul.select2-selection__rendered li').first().text()
  • Related