[c#htmlAgilityPack从id块读取,直到另一个id块

问题描述 投票:-2回答:1

我有这样的HTML文档

   <tr  id="__TOC_1">

                                <div id="AUTOGENBOOKMARK_3_7899df20-f104-434d-a5e4-fa293412f5db">
                                    <div style="visibility:hidden">&nbsp;</div>
                                </div>
                                <div>District name</div>
                                <div>July&nbsp;&nbsp;&nbsp;&nbsp; 2019</div>
                                <div>Something</div>
                                <div>Something</div>
                                <div>Address</div>
                                <div>
                                    <div style="visibility:hidden">&nbsp;</div>
                                </div>
                                <div>
                                    <div style="visibility:hidden">&nbsp;</div>
                                </div>
                        </tr>

<tr>
                            <td class="style_6" >
                                <div class="style_7" id="AUTOGENBOOKMARK_4_d4d6">Apartment number.</div>
                            </td>
                            <td class="style_6" s>
                                <div class="style_7" id="AUTOGENBOOKMARK_5_87b456a7" >Personal account</div>
                            </td>
                            <td class="style_6">
                                <div class="style_7" id="AUTOGENBOOKMARK_6_2b05c0c6>Accrued</div>
                            </td>
                            <td class="style_6" >
                                <div class="style_7" id="AUTOGENBOOKMARK_7_f66f8084>Received</div>
                            </td>
                        </tr>
<tr>
                            <td class="style_6">
                                <div>195</div>
                            </td>
                            <td class="style_6">
                                <div>00060631402</div>
                            </td>
                            <td class="style_6">
                                <div>155.63</div>
                            </td>
                            <td class="style_6">
                                <div">155.63</div>
                            </td>

    <tr>
                            <td class="style_6">
                                <div>Total</div>
                            </td>
                            <td class="style_6">
                                <div>30</div>
                            </td>
                            <td class="style_6">
                                <div>0.00</div>
                            </td>
                            <td class="style_6">
                                <div>271.04</div>
                            </td>
                        </tr>

并且此代码与__TOC_2 ...__ TOC_3 ..和下一个重复n次

我需要输入地区名称,月份日期,跳过下一个区域并获取所有信息,直到总计

并且我想将其写入我的对象

 public class PaymentInfo
{
    public string District { get; set; }

    public string PaymentDate { get; set; }

    public string Address { get; set; }
}

 public class Payment
{
    public string ApartmentNumber { get; set; }

    public int PersonalAccount { get; set; }

    public decimal Accrued { get; set; }

    public decimal Received { get; set; }
}

我认为我需要阅读表单的第一个id块,直到另一个,但我不明白如何停止和过滤信息。

c# html html-agility-pack
1个回答
0
投票

您通过xpath start-with获得了这些节点>

//tr[starts-with(@id,'__TOC')]
© www.soinside.com 2019 - 2024. All rights reserved.