Tuesday 30 May 2017

Node.js Cheerio Parse html table inside a html table

<table cellspacing="0" cellpadding="0" width="90%" align="center" border="0">       
        <tr>
            <td>

                        <table cellpadding="0" cellspacing="1" width="90%" border="0" align="center">
                            <tr>
                                <td

The whole second table is inside the td tag of the first table.

I am new to cheerio. I can't quite get my output to give me only the inner tables tr values. I get both tables and it's messy.

$ = cheerio.load(html.toString());
var data = [];
    $('tr').each(function(i, tr){

        var children = $(this).children();
        var itemNum = children.eq(0);

        var row = {
            "Num": itemNum.text().trim()
        };
        data.push(row);
        console.log(row);
    });    



via user3911976

No comments:

Post a Comment