用Cheerio解析表

时间:2017-09-18 05:08:45

标签: jquery cheerio

\n

所以这是看起来很奇怪的HTMl结构。我想要的元素是我在HTML中标记的元素。

这是我用来解析HTML的Node Js代码。我对jQuery不是很熟悉。

<html>
<body>
    <table>
        <tbody>
            <tr>
                <!-- More things here -->
            </tr>
            <tr>
                <td>
                    <table></table>
                    <table>
                        <tbody>
                            <tr>
                                <td></td>
                                <td>I want this</td>
                            </tr>
                        </tbody>
                    </table>
                    <table></table>
                </td>
            </tr>
            <tr>
               <!-- More things here -->
            </tr>
        </tbody>
    </table>
</body>
</html>

1 个答案:

答案 0 :(得分:4)

如果您显示的结构是固定的(行数等)......

$('table tr:nth-child(2) table:nth-child(2) tr td:nth-child(2)').text()

我希望它有所帮助