Im using cheerio but dont know how to access lists inside lists. so far it adds html elements not separated but adds them together. What am I doing wrong? Very helpful for any help!!!
the html:
...
<div classname="main">
<div classname="content">
<div classname="somethingElse">
<div classname="list">
<div classname="item">
<div>
<div>
<ul classname="name-wrapper">
<li classname="name">
<span>
title
</span>
<span>
info
</span>
</li>
</ul>
</div>
</div>
</div>
<div classname="item">
<div>
<div className="container">
<ul classname="name-wrapper">
<li classname="name">
<span>
other title
</span>
<span>
other info
</span>
</li>
</ul>
</div>
</div>
</div>
<div classname="item">
...
</div>
...
</div>
</div>
</div>
</div>
const extractContent= $ => {
return $('.main .content .list .item')
.map((_, item) => {
const $item = $(item);
return {
...
title: $item.find('.name-wrapper span:nth-of-type(1)').text(),
info: $item.find('.name-wrapper span:nth-of-type(2)').text(),
createdAt: new Date()
...
}
}).toArray();
}
I receive for title:
title other title
I receive for info:
info other info