gpt4 book ai didi

c# - 如果 Html 文件没有结尾 "/tr"标记或 "/td"标记,则 HTML Agility Pack 无法完美读取该信息

转载 作者:太空狗 更新时间:2023-10-29 21:55:56 27 4
gpt4 key购买 nike

我正在使用 HTML Agility Pack 来解析 html 内容。我正在使用解析来提取表信息。有用。但是,如果没有结尾的“/tr”标签或“/td”标签,那么它就不能完美地解析该信息。(其中没有结尾的 tr 标签或 td 标签。)

喜欢

    <html>
<head>
<meta name="generator" content=
"HTML Tidy for Windows (vers 14 February 2006), see www.w3.org">
<title></title>
</head>
<body>
<table cellspacing="0" cellpadding="0" width="100%" border="0">
<tbody>
<tr>
<td class="xl27" valign="bottom" colspan="9">
Sir / Madam,<br>
I/We have this day done by your order and on your account the
following transactions:
</td>
<td class="xl27boTRL" align="middle" colspan="5">
Stamp duty as required under the relevant stamp act to be paid on
consolidated basis at the end of the month.
</td>
</tr>
<tr height="30">
<td class="xl27boTBL" align="middle" width="7%">
Order No
</td>
<td class="xl27boTBL" align="middle" width="4%">
Order Time
</td>

<td class="xl27boTBL" align="middle" width="5%">
Net Rate
</td>
<td class="xl27boTBL" align="middle" width="5%">
Service Tax
</td>
<td class="xl27boTBL" align="middle" width="5%">
Amount
</td>
<td class="xl27boTRBL" style="BORDER-BOTTOM: windowtext 1pt solid;"
align="middle" width="8%">
Net Amount Rs
</td>
</tr>
<tr height="20">
<td class="xl27boL" nowrap width="7%">
25222105
</td>
<td class="xl27boL" nowrap width="4%">
14:02:39
</td>


<td class="xl27boL" nowrap align="right" width="5%">
 
</td>
<td class="xl27boL" nowrap align="right" width="5%">
 
</td>
<td class="xl27boRL" nowrap align="right" width="8%">
125288.00 
</td>

<tr height="20">
<td class="xl27boL" nowrap width="7%">
122122141
</td>
<td class="xl27boL" nowrap width="4%">
14:01:56
</td>


<td class="xl27boL" nowrap align="right" width="5%">
 
</td>
<td class="xl27boL" nowrap align="right" width="5%">
 
</td>
<td class="xl27boRL" nowrap align="right" width="8%">
249612.64 
</td>

<tr height="20">
<td class="xl27boL" nowrap width="7%">
 
</td>
<td class="xl27boL" nowrap width="4%">
 
</td>
<td class="xl27boL" nowrap width="7%">
 
</td>
<td class="xl27boL" nowrap width="4%">
 
</td>
<td class="xl27boL" nowrap align="left" width="15%">
[SERVICE TAX]
</td>
<td class="xl27boL" nowrap align="right" width="5%">
 
</td>
<td class="xl27boL" nowrap align="right" width="5%">
 
</td>
<td class="xl27boL" nowrap align="right" width="5%">
 
</td>
<td class="xl27boL" nowrap align="right" width="7%">
 
</td>
<td class="xl27boL" nowrap align="right" width="5%">
 
</td>
<td class="xl27boL" nowrap align="right" width="5%">
 
</td>
<td class="xl27boL" nowrap align="right" width="5%">
 
</td>
<td class="xl27boL" nowrap align="right" width="5%">
 
</td>
<td class="xl27boRL" nowrap align="right" width="8%">
61.66
</td>
</tr>
</tbody>
</table>
</body>
</html>

那么我应该怎么做呢?

<TABLE  cellpadding=1 cellspacing=0 Width='100%'  style='border:1px solid #FFFFFF;''>
<TRAlign='middle' VAlign='bottom' Class='clsTRFontBold'>
<TD NoWrap class=clsTRFontHdr>ORDER NO</TD><TD NoWrap class=clsTRFontHdr>ORD TIME</TD>
<TD NoWrap class=clsTRFontHdr>TRADE NO</TD><TD NoWrap class=clsTRFontHdr>TRD TIME</TD>
<TD NoWrap class=clsTRFontHdr ALIGN=CENTER>SCRIPNAME</TD>
<TD NoWrap class=clsTRFontHdr>BUY/SELL</TD><TD NoWrap class=clsTRFontHdr>QUANTITY</TD>
<TD NoWrap class=clsTRFontHdr align=right>RATE (RS)</TD>
<TD NoWrap class=clsTRFontHdr align=right>TOTAL (RS)</TD>
<TD NoWrap class=clsTRFontHdr align=right>TOT BROK (RS)</TD>
<TD NoWrap class=clsTRFontHdr align=right>SER TAX (RS)</TD>
<TD NoWrap class=clsTRFontHdr align=right>STT (RS)</TD>
<TD NoWrap class=clsTRFontHdr align=right>NET TOTAL (RS)</TD>
</TR>

<TR Class='clsTRFont'>
<TD NoWrap>2009030267182768</TD>
<TD NoWrap>10:28:11</TD><TD NoWrap>66950592</TD>
<TD NoWrap>10:28:25</TD>
<TD NoWrap>SESA GOA LTD</TD>
<TD NoWrap>BUY</TD>
<TD NoWrap ALIGN='RIGHT'>366 </TD>
<TD NoWrap ALIGN='RIGHT'>78.2000</TD>
<TD NoWrap ALIGN='RIGHT'>28621.20</TD>
<TD NoWrap ALIGN='RIGHT'>0.01</TD>
<TD NoWrap ALIGN='RIGHT'>0.00</TD><TD NoWrap ALIGN='RIGHT'>0.00</TD>
<TD NoWrap ALIGN='RIGHT'>-28621.21</TD></TR>
<!--tr tag missing-->
<TD NoWrap>2009030267182768</TD>
<TD NoWrap>10:28:11</TD><TD NoWrap>66950783</TD><TD NoWrap>10:28:27</TD>
<TD NoWrap>SESA GOA LTD</TD><TD NoWrap>BUY</TD><TD NoWrap ALIGN='RIGHT'>100 </TD>
<TD NoWrap ALIGN='RIGHT'>78.2000</TD><TD NoWrap ALIGN='RIGHT'>7820.00</TD>
<TD NoWrap ALIGN='RIGHT'>0.01</TD><TD NoWrap ALIGN='RIGHT'>0.00</TD>
<TD NoWrap ALIGN='RIGHT'>0.00</TD><TD NoWrap ALIGN='RIGHT'>-7820.01</TD>
</TR>
<!--tr tag missing-->
<TD NoWrap>2009030267182768</TD><TD NoWrap>10:28:11</TD>
<TD NoWrap>66956828</TD><TD NoWrap>10:29:39</TD><TD NoWrap>SESA GOA LTD</TD>
<TD NoWrap>BUY</TD><TD NoWrap ALIGN='RIGHT'>534 </TD>
<TD NoWrap ALIGN='RIGHT'>78.2000</TD><TD NoWrap ALIGN='RIGHT'>41758.80</TD>
<TD NoWrap ALIGN='RIGHT'>0.01</TD><TD NoWrap ALIGN='RIGHT'>0.00</TD>
<TD NoWrap ALIGN='RIGHT'>0.00</TD><TD NoWrap ALIGN='RIGHT'>-41758.81</TD>
</TR>
<!--tr tag missing-->
<TD NoWrap>2009030267510894</TD><TD NoWrap>11:06:12</TD><TD NoWrap>67137258</TD>
<TD NoWrap>11:09:24</TD><TD NoWrap>SESA GOA LTD</TD><TD NoWrap>SELL</TD>
<TD NoWrap ALIGN='RIGHT'>162 </TD><TD NoWrap ALIGN='RIGHT'>78.2500</TD>
<TD NoWrap ALIGN='RIGHT'>12676.50</TD><TD NoWrap ALIGN='RIGHT'>0.01</TD>
<TD NoWrap ALIGN='RIGHT'>0.00</TD><TD NoWrap ALIGN='RIGHT'>3.1320</TD>
<TD NoWrap ALIGN='RIGHT'>12673.36</TD></TR><TD NoWrap>2009030267510894</TD>
<TD NoWrap>11:06:12</TD><TD NoWrap>67137465</TD><TD NoWrap>11:09:28</TD>
<TD NoWrap>SESA GOA LTD</TD><TD NoWrap>SELL</TD><TD NoWrap ALIGN='RIGHT'>200 </TD>
<TD NoWrap ALIGN='RIGHT'>78.2500</TD><TD NoWrap ALIGN='RIGHT'>15650.00</TD>
<TD NoWrap ALIGN='RIGHT'>0.01</TD><TD NoWrap ALIGN='RIGHT'>0.00</TD>
<TD NoWrap ALIGN='RIGHT'>4.1010</TD><TD NoWrap ALIGN='RIGHT'>15645.89</TD>
</TR>
<!--tr tag missing-->
<TD NoWrap>2009030267510894</TD><TD NoWrap>11:06:12</TD>
<TD NoWrap>67137479</TD><TD NoWrap>11:09:28</TD><TD NoWrap>SESA GOA LTD</TD>
<TD NoWrap>SELL</TD><TD NoWrap ALIGN='RIGHT'>4 </TD>
<TD NoWrap ALIGN='RIGHT'>78.2500</TD><TD NoWrap ALIGN='RIGHT'>313.00</TD>
<TD NoWrap ALIGN='RIGHT'>0.01</TD><TD NoWrap ALIGN='RIGHT'>0.00</TD>
<TD NoWrap ALIGN='RIGHT'>0.0773</TD><TD NoWrap ALIGN='RIGHT'>312.91</TD>
</TR>
<!--tr tag missing-->
<TD NoWrap>2009030267510894</TD><TD NoWrap>11:06:12</TD><TD NoWrap>67137995</TD>
<TD NoWrap>11:09:32</TD><TD NoWrap>SESA GOA LTD</TD><TD NoWrap>SELL</TD>
<TD NoWrap ALIGN='RIGHT'>16 </TD><TD NoWrap ALIGN='RIGHT'>78.2500</TD>
<TD NoWrap ALIGN='RIGHT'>1252.00</TD><TD NoWrap ALIGN='RIGHT'>0.01</TD>
<TD NoWrap ALIGN='RIGHT'>0.00</TD><TD NoWrap ALIGN='RIGHT'>0.3093</TD>
<TD NoWrap ALIGN='RIGHT'>1251.68</TD></TR>
<!--tr tag missing-->
<TD NoWrap>2009030267510894</TD>
<TD NoWrap>11:06:12</TD><TD NoWrap>67138097</TD><TD NoWrap>11:09:34</TD>
<TD NoWrap>SESA GOA LTD</TD><TD NoWrap>SELL</TD><TD NoWrap ALIGN='RIGHT'>100 </TD>
<TD NoWrap ALIGN='RIGHT'>78.2500</TD><TD NoWrap ALIGN='RIGHT'>7825.00</TD>
<TD NoWrap ALIGN='RIGHT'>0.01</TD><TD NoWrap ALIGN='RIGHT'>0.00</TD>
<TD NoWrap ALIGN='RIGHT'>1.9333</TD><TD NoWrap ALIGN='RIGHT'>7823.06</TD>
</TR>
<!--tr tag missing-->
<TD NoWrap>2009030267510894</TD><TD NoWrap>11:06:12</TD><TD NoWrap>67138333</TD><TD NoWrap>11:09:39</TD><TD NoWrap>SESA GOA LTD</TD><TD NoWrap>SELL</TD><TD NoWrap ALIGN='RIGHT'>200 </TD><TD NoWrap ALIGN='RIGHT'>78.2500</TD><TD NoWrap ALIGN='RIGHT'>15650.00</TD><TD NoWrap ALIGN='RIGHT'>0.01</TD><TD NoWrap ALIGN='RIGHT'>0.00</TD><TD NoWrap ALIGN='RIGHT'>3.8666</TD><TD NoWrap ALIGN='RIGHT'>15646.12</TD>
</TR>
<!--tr tag missing-->
<TD NoWrap>2009030267510894</TD><TD NoWrap>11:06:12</TD><TD NoWrap>67138344</TD><TD NoWrap>11:09:40</TD><TD NoWrap>SESA GOA LTD</TD><TD NoWrap>SELL</TD><TD NoWrap ALIGN='RIGHT'>318 </TD><TD NoWrap ALIGN='RIGHT'>78.2500</TD><TD NoWrap ALIGN='RIGHT'>24883.50</TD><TD NoWrap ALIGN='RIGHT'>0.01</TD><TD NoWrap ALIGN='RIGHT'>0.00</TD><TD NoWrap ALIGN='RIGHT'>6.1479</TD><TD NoWrap ALIGN='RIGHT'>24877.34</TD>
</TR>
<!--tr tag missing-->
<TD NoWrap>2009030268222556</TD><TD NoWrap>13:03:50</TD><TD NoWrap>67511545</TD><TD NoWrap>13:03:51</TD><TD NoWrap>SESA GOA LTD</TD><TD NoWrap>BUY</TD><TD NoWrap ALIGN='RIGHT'>733 </TD><TD NoWrap ALIGN='RIGHT'>78.0000</TD><TD NoWrap ALIGN='RIGHT'>57174.00</TD><TD NoWrap ALIGN='RIGHT'>0.01</TD><TD NoWrap ALIGN='RIGHT'>0.00</TD><TD NoWrap ALIGN='RIGHT'>0.00</TD><TD NoWrap ALIGN='RIGHT'>-57174.01</TD>
</TR>
<!--tr tag missing-->
<TD NoWrap>2009030268222556</TD><TD NoWrap>13:03:50</TD><TD NoWrap>67511621</TD><TD NoWrap>13:03:53</TD><TD NoWrap>SESA GOA LTD</TD><TD NoWrap>BUY</TD><TD NoWrap ALIGN='RIGHT'>2 </TD><TD NoWrap ALIGN='RIGHT'>78.0000</TD><TD NoWrap ALIGN='RIGHT'>156.00</TD><TD NoWrap ALIGN='RIGHT'>0.01</TD><TD NoWrap ALIGN='RIGHT'>0.00</TD><TD NoWrap ALIGN='RIGHT'>0.00</TD><TD NoWrap ALIGN='RIGHT'>-156.01</TD>
</TR>
<!--tr tag missing-->
<TD NoWrap>2009030268222556</TD><TD NoWrap>13:03:50</TD><TD NoWrap>67511797</TD><TD NoWrap>13:03:58</TD><TD NoWrap>SESA GOA LTD</TD><TD NoWrap>BUY</TD><TD NoWrap ALIGN='RIGHT'>1 </TD><TD NoWrap ALIGN='RIGHT'>78.0000</TD><TD NoWrap ALIGN='RIGHT'>78.00</TD><TD NoWrap ALIGN='RIGHT'>0.01</TD><TD NoWrap ALIGN='RIGHT'>0.00</TD><TD NoWrap ALIGN='RIGHT'>0.00</TD><TD NoWrap ALIGN='RIGHT'>-78.01</TD>
</TR>
<!--tr tag missing-->
<TD NoWrap>2009030268222556</TD><TD NoWrap>13:03:50</TD><TD NoWrap>67512082</TD><TD NoWrap>13:04:05</TD><TD NoWrap>SESA GOA LTD</TD><TD NoWrap>BUY</TD><TD NoWrap ALIGN='RIGHT'>264 </TD><TD NoWrap ALIGN='RIGHT'>78.0000</TD><TD NoWrap ALIGN='RIGHT'>20592.00</TD><TD NoWrap ALIGN='RIGHT'>0.01</TD><TD NoWrap ALIGN='RIGHT'>0.00</TD><TD NoWrap ALIGN='RIGHT'>0.00</TD><TD NoWrap ALIGN='RIGHT'>-20592.01</TD>
</TR>
<!--tr tag missing-->
<TD NoWrap>2009030268378000</TD><TD NoWrap>13:31:04</TD><TD NoWrap>67609079</TD><TD NoWrap>13:33:39</TD><TD NoWrap>SESA GOA LTD</TD><TD NoWrap>BUY</TD><TD NoWrap ALIGN='RIGHT'>405 </TD><TD NoWrap ALIGN='RIGHT'>77.6000</TD><TD NoWrap ALIGN='RIGHT'>31428.00</TD><TD NoWrap ALIGN='RIGHT'>0.01</TD><TD NoWrap ALIGN='RIGHT'>0.00</TD><TD NoWrap ALIGN='RIGHT'>0.00</TD><TD NoWrap ALIGN='RIGHT'>-31428.01</TD>
</TR>
<!--tr tag missing-->
<TD NoWrap>2009030268378000</TD><TD NoWrap>13:31:04</TD><TD NoWrap>67609374</TD><TD NoWrap>13:33:46</TD><TD NoWrap>SESA GOA LTD</TD><TD NoWrap>BUY</TD><TD NoWrap ALIGN='RIGHT'>45 </TD><TD NoWrap ALIGN='RIGHT'>77.6000</TD><TD NoWrap ALIGN='RIGHT'>3492.00</TD><TD NoWrap ALIGN='RIGHT'>0.01</TD><TD NoWrap ALIGN='RIGHT'>0.00</TD><TD NoWrap ALIGN='RIGHT'>0.00</TD><TD NoWrap ALIGN='RIGHT'>-3492.01</TD>
</TR>
<!--tr tag missing-->
<TD NoWrap>2009030268779359</TD><TD NoWrap>14:32:04</TD><TD NoWrap>67870192</TD><TD NoWrap>14:32:41</TD><TD NoWrap>SESA GOA LTD</TD><TD NoWrap>BUY</TD><TD NoWrap ALIGN='RIGHT'>900 </TD><TD NoWrap ALIGN='RIGHT'>77.3000</TD><TD NoWrap ALIGN='RIGHT'>69570.00</TD><TD NoWrap ALIGN='RIGHT'>0.01</TD><TD NoWrap ALIGN='RIGHT'>0.00</TD><TD NoWrap ALIGN='RIGHT'>0.00</TD><TD NoWrap ALIGN='RIGHT'>-69570.01</TD>
</TR>
<!--tr tag missing-->
<TD NoWrap>2009030269013760</TD><TD NoWrap>15:03:56</TD><TD NoWrap>68018179</TD><TD NoWrap>15:03:56</TD><TD NoWrap>SESA GOA LTD</TD><TD NoWrap>SELL</TD><TD NoWrap ALIGN='RIGHT'>146 </TD><TD NoWrap ALIGN='RIGHT'>76.2500</TD><TD NoWrap ALIGN='RIGHT'>11132.50</TD><TD NoWrap ALIGN='RIGHT'>0.01</TD><TD NoWrap ALIGN='RIGHT'>0.00</TD><TD NoWrap ALIGN='RIGHT'>2.8226</TD><TD NoWrap ALIGN='RIGHT'>11129.67</TD>
</TR>
<!--tr tag missing-->
<TD NoWrap>2009030269013760</TD><TD NoWrap>15:03:56</TD><TD NoWrap>68018180</TD><TD NoWrap>15:03:56</TD><TD NoWrap>SESA GOA LTD</TD><TD NoWrap>SELL</TD><TD NoWrap ALIGN='RIGHT'>10 </TD><TD NoWrap ALIGN='RIGHT'>76.2500</TD><TD NoWrap ALIGN='RIGHT'>762.50</TD><TD NoWrap ALIGN='RIGHT'>0.01</TD><TD NoWrap ALIGN='RIGHT'>0.00</TD><TD NoWrap ALIGN='RIGHT'>0.1933</TD><TD NoWrap ALIGN='RIGHT'>762.30</TD>
</TR>
<TABLE cellpadding=0 cellspacing=0 border=0><br>

最佳答案

既然你测试了我的另一个想法,但没有奏效,我想你只有两个选择:

  1. 修改 HTML Agility Pack 来处理您的情况,或者
  2. 填写缺失的</tr>是你自己。

这是一个正则表达式,可以填充缺失的 </tr>给你:

html = Regex.Replace(html, "<tr[^>]*>(?:(?!</?tr>|</tbody>|</table>).)*?(?=<tr[^>]*>|</tbody>|</table>)", "$&</tr>", RegexOptions.Singleline | RegexOptions.IgnoreCase);

(如果有人可以改进我的正则表达式,请随意。)

关于c# - 如果 Html 文件没有结尾 "/tr"标记或 "/td"标记,则 HTML Agility Pack 无法完美读取该信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2477426/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com