技术开发 频道

用C#和正则表达式截取html代码

  【IT168技术文档】如何使用C#和正则表达式截取html代码呢,如何处理html代码中的\r\n这样的字符呢,下面我们来一起研究一下,先从截取目标开始。

 一、代码说明

 1.以下html表示收到的3个组的信息,如果含有"unread.gif"表示未读消息,否则表示已读信息。

 2.截取未读消息和已读消息的条数和theUrl

 3.要将未读信息和已读信息分开放入两个组里。

 <div class="dxx_of" id="message1" onmouseover="msgOnmouseover(1)" onmouseout="msgOnmouseout(1)" />

 <div class="dxx1" style="padding:15px 10px;"><img src="http://www.microsoft.com/i2/unread.gif" width="14" height="10" title="" /></div>

 <div class="dxx2">

 <table class="aa" border="0" cellpadding="0" cellspacing="0" >

 <colgroup>

 <col width="463" />

 </colgroup>

 <tbody>

 <tr basestyle="oRowLine2">

 <td valign="top" onclick="javascript:document.location='thUrl';" >

 wa

 <div><span class='c9'>共6条会话</span><a href="thUrl" class="sl">+展开</a></span></div>

 <span class="c9"></span>

 </td>

 </tr>

 </tbody>

 </table>

 </div>

 <div class="c"></div>

 </div>

 <div class="dxx_of" id="message2" onmouseover="msgOnmouseover(2)" onmouseout="msgOnmouseout(2)" />

 <div class="dxx1" style="padding:15px 10px;"></div>

 <div class="dxx2">

 <table class="aa" border="0" cellpadding="0" cellspacing="0" >

 <colgroup>

 <col width="463" />

 </colgroup>

 <tbody>

 <tr basestyle="oRowLine2">

 <td valign="top" onclick="javascript:document.location='thUrl';" >

 wa

 <div><span class='c9'>共3条会话</span><a href="thUrl1" class="sl">+展开</a></span></div>

 <span class="c9"></span>

 </td>

 </tr>

 </tbody>

 </table>

 </div>

 <div class="c"></div>

 </div>

 <div class="dxx_of" id="message3" onmouseover="msgOnmouseover(3)" onmouseout="msgOnmouseout(3)" />

 <div class="dxx1" style="padding:15px 10px;"></div>

 <div class="dxx2">

 同上很多html内容

 </div>

 <div class="c"></div>

 </div>

 
0
相关文章