K
K
KamMif2016-12-15 22:02:40
Ruby on Rails
KamMif, 2016-12-15 22:02:40

How to parse child elements in Nokogiri?

Hello everyone, the essence of the voros, you need to parse the elements of the table, only there is a class with a specific name in one of the cells of the table:

<body>
    <div class="content">
        <table class="normal">
            <tbody>
                <tr>
                    <td class="name">Hello</td>
                    <td></td>
                    <td></td>
                    <td class="count"></td>
                    <td></td>
                    <td class="parse this"></td>
                    <td class="parse this"></td>
                    <td class="parse this"></td>
                    <td></td>
                    <td></td>
                    <td></td>
                </tr>
                <tr>
                    <td class="name">Hello</td>
                    <td></td>
                    <td></td>
                    <td class="count"></td>
                    <td></td>
                    <td></td>
                    <td class="parse this"></td>
                    <td class="parse this"></td>
                    <td></td>
                    <td></td>
                    <td></td>
                </tr>
                <tr>
                    <td class="name">Hello</td>
                    <td></td>
                    <td></td>
                    <td class="count"></td>
                    <td></td>
                    <td class="parse this"></td>
                    <td></td>
                    <td class="parse this"></td>
                    <td></td>
                    <td></td>
                    <td></td>
                </tr>
                <tr>
                    <td class="name">Hello</td>
                    <td></td>
                    <td></td>
                    <td class="count"></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                </tr>
                <tr>
                    <td class="name">Hello</td>
                    <td></td>
                    <td></td>
                    <td class="count"></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                </tr>
                
            </tbody>
        </table>
    </div>
</body>

how to parse cell values ​​.name and .count only for those whose td's with index are equal to .parse this
Thanks for the help

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilya, 2016-12-15
@glebovgin

Good afternoon.
If Nokogiri knows how to use xpath, then this is how you get all name
By analogy, you will find count. Xpath rules.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question