I am changing a question inserted yesterday, and answered correctly.
I have to parse an html page organized this way:
<li id="list">
<ul>
<li>
<a class="region">Liguria</a>
<ul>
<li>
<a class="city">Genova</a>
</li>
<li>
<a class="city">Savona</a>
</li>
</ul>
</li>
<li>
<a class="region">Lazio</a>
<ul>
<li>
<a class="city">Roma</a>
</li>
</ul>
</li>
</ul>
</li>
I need to extract an object with the regions and the cities, like this:
result = {
'Liguria': [
'Genova' , 'Savona',
],
'Lazio': [ 'Roma', ],
};
I am using cheerio from node.js, but I added jquery to the tags since cheerio uses jquery-style selector (AFAIK...).
I have come with this partial solution, which is not working ...
$('li[id="list"] ul li').each(function(i, elem) {
console.log('region:', $(this).html());
// work on each li containing the region to get the cities...
// ???
});
As you can see, I'm quite confused... :-(
Any clue?