2
<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);
    });    
0

1 Answer 1

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

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

This code fixed the issue. I didn't realize you just pass the elements til you get to the one you need then using children.eq(n) i was able to get each td text value within the row. Hopefully this can help someone else.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.