读取html里table的值
数据如下,就是两个table,省略了很多,但就是这个规律!
想读取html里Table一些有规律的数据(1,008,999,1,518)做比较,选出最大值和最小值,请问怎么读取,
我只会把Table读取到一个textbox里面,但不知道怎么读取自己需要的!
- HTML code
<table><tr><td c><b></b></td><td colspan="4" ><b>B</b></td><td colspan="4" id='fl_a' class='t'><b>C</b></td><td colspan="4"><b>D</b></td></tr><tr class='fl'><th><b>test</b></th> <th><b>test</b></th> <th><b>test</b></th> <th style='border-right:solid 1px #B8B8B8' ;=""><b>test</b></th><th><b>test</b></th> <th><b>test</b></th> <th><b>test</b></th> <th style='border-right:solid 1px #B8B8B8' ;=""><b>test</b></th><th><b>test</b></th> <th><b>test</b></th> <th><b>test</b></th> <th style='border-right:solid 1px #B8B8B8' ;=""><b>test</b></th><th><b>test</b></th> <th><b>test</b></th> <th><b>test</b></th> <th style='border-right:solid 1px #B8B8B8' ;=""><b>test</b></th></tr><tr align="center" bgcolor="#FFFFFF" class='floor'><td id="ttt" name="ddd" bgcolor="#FFFFFF" style='padding:0;'> <nobr> <font color="#0000FF"> <div id="yyy" name="iii" style="width:100%;height:100%;cursor:pointer;color:#157FC5;"> [color=#FF0000]1,008[/color]</div> </font> </nobr> </td> <td id="test" name="test" bgcolor="#FFFFFF"><nobr> <font color="#0000FF"> <div id="ppp" name="ooo" style="width:100%;height:100%;cursor:pointer;color:#157FC5;"> 583</div> </font> </nobr> </td> <td id="test" name="test" bgcolor="#FFFFFF" style='padding:0;'><nobr> <font color="#0000FF"> <div id="023123" name="0899859" style="width:100%;height:100%;cursor:pointer;color:#157FC5;"> 06年</div> </font> </nobr> </td> <td id="test" name="test" bgcolor="#FFFFFF"><nobr> <font color="#0000FF"> <div id="0899859" name="859" style="width:100%;height:100%;cursor:pointer;color:#157FC5;"> <span id="9_td_span" style='color:#09B211;'> 51.0% </span> </div> </font> </nobr> </td><td id="test" name="test" bgcolor="#FFFFFF" style='padding:0;'> <nobr> <font color="#0000FF"> <div id="sss" name="aaa" style="width:100%;height:100%;cursor:pointer;color:#157FC5;"> [color=#FF0000] 999[/color] </div> </font> </nobr> </td> <td>08</td> <td>36%</td></table><table>..............<td id="ttt" name="ddd" bgcolor="#FFFFFF" style='padding:0;'> <nobr> <font color="#0000FF"> <div id="yyy" name="iii" style="width:100%;height:100%;cursor:pointer;color:#157FC5;"> [color=#FF0000]1,518[/color]</div> </font> </nobr> </td>
[解决办法]
正则获取div中内容Regex reg = new Regex(@"(? is)<div[^>]*>(.+?)</div>")
[解决办法]
随便取得两个,
- C# code
string iHtml = @" <nobr> <font color=""#0000FF""> <div id=""sss"" name=""aaa"" style=""width:100%;height:100%;cursor:pointer;color:#157FC5;""> 999 </div> </font> </nobr> <nobr> <font color=""#0000FF""> <div id=""yyy"" name=""iii"" style=""width:100%;height:100%;cursor:pointer;color:#157FC5;""> 1,518</div> </font> </nobr> "; List<string> htmllist = new List<string>(); foreach (Match m in System.Text.RegularExpressions.Regex.Matches(iHtml,@"(?is)<nobr>\s*<font\s*color=""#0000FF"">\s*<div[^>]*?>(.*?)</div>\s*</font>")) { htmllist.Add(m.Groups[1].Value); } htmllist.ForEach(A => Console.Write(A));
[解决办法]
1.正则
2.用 JS 的伪对象 循环处理。