Html Agility Pack循环通过特定行

时间:2018-04-05 05:01:17

标签: xpath html-agility-pack

我有一张这样的表

<table>
<thead>
    <tr>
        <th>Name</th>
        <th>Department</th>
        <th>Gender</th>
    </tr>
</thead>
<tbody>
    <tr id="data1">

    </tr>
    <tr>

    </tr>
</tbody>

我想使用Html Agility Pack来解析它的特定行,即我想显示具有id = data1的行旁边的行

下面是我正在尝试的代码...

        //Selecting Document Node....

        HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
        doc.LoadHtml(data);

        //Selecting Specific Node...

        var tableNodes = doc.DocumentNode.SelectNodes("//table");

1 个答案:

答案 0 :(得分:0)

你的xpath应该是这样的: //table/tbody/tr[@id='data1']/following-sibling::tr