下面是从网页中得到的html代码部分,现在需要提取每个<LI><SPAN class="userPic"><A> </A></SPAN></LI>中的title和href的属性值,以及<SPAN class=topData></SPAN>中的值,例如第一个为 :胡立阳 huliyang 4123451 ,请问如何操作?
<LI class="userList t2"><EM class=ico_num>10</EM> <EM class="ico_state "></EM><SPAN class=userPic><A title=胡立阳(@胡立阳) href="/huliyang" rel=胡立阳(@胡立阳) 1333183314493="10" card="1" ctype="2"><IMG alt=胡立阳(@胡立阳) src="http://t2.qlogo.cn/mbloghead/6a691dce320cc164bdae/40"></A></SPAN><SPAN class=userName><A title=胡立阳(@胡立阳) href="/huliyang" rel=胡立阳(@胡立阳) 1333183314493="60" card="1" ctype="2">胡立阳</A></SPAN><SPAN class=topData>4123451</SPAN><SPAN class=pint>胡立阳,华尔街股市神童、亚洲股市教父,美国加州圣塔克...</SPAN> 
<DIV class=attentBox><INPUT class=addAttention value="收听<i class=\'l\'></i>" type=button><A style="DISPLAY: none" class=delAttention href="http://t.qq.com/rank.php?id=5&amp;p=1#">取消<I class=l></I></A><A style="DISPLAY: none" class=delAttention href="#">取消<I class="\'l\'"></I></A></DIV></LI>
<LI class="userList "><EM class=ico_num>11</EM> <EM class="ico_state "></EM><SPAN class=userPic><A title=经纬张颖(@经纬张颖) href="/matrixdavidzhang" rel=经纬张颖(@经纬张颖) 1333183314493="11" card="1" ctype="2"><IMG alt=经纬张颖(@经纬张颖) src="http://t0.qlogo.cn/mbloghead/d30b0807601b9a9dc36c/40"></A></SPAN><SPAN class=userName><A title=经纬张颖(@经纬张颖) href="/matrixdavidzhang" rel=经纬张颖(@经纬张颖) 1333183314493="61" card="1" ctype="2">经纬张颖</A></SPAN><SPAN class=topData>3487264</SPAN><SPAN class=pint>张颖,经纬中国创始人、分众传媒董事、新浪乐居董事。投...</SPAN> 
<DIV class=attentBox><INPUT class=addAttention value="收听<i class=\'l\'></i>" type=button><A style="DISPLAY: none" class=delAttention href="http://t.qq.com/rank.php?id=5&amp;p=1#">取消<I class=l></I></A><A style="DISPLAY: none" class=delAttention href="#">取消<I class="\'l\'"></I></A></DIV></LI>

解决方案 »

  1.   

    新建一个txt<LI class="userList t2"><EM class=ico_num>10</EM> <EM class="ico_state "></EM><SPAN class=userPic><A title=胡立阳(@胡立阳) href="/huliyang" rel=胡立阳(@胡立阳) 1333183314493="10" card="1" ctype="2"><IMG alt=胡立阳(@胡立阳) src="http://t2.qlogo.cn/mbloghead/6a691dce320cc164bdae/40"></A></SPAN><SPAN class=userName><A title=胡立阳(@胡立阳) href="/huliyang" rel=胡立阳(@胡立阳) 1333183314493="60" card="1" ctype="2">胡立阳</A></SPAN><SPAN class=topData>4123451</SPAN><SPAN class=pint>胡立阳,华尔街股市神童、亚洲股市教父,美国加州圣塔克...</SPAN> 
    <DIV class=attentBox><INPUT class=addAttention value="收听<i class=\'l\'></i>" type=button><A style="DISPLAY: none" class=delAttention href="http://t.qq.com/rank.php?id=5&amp;p=1#">取消<I class=l></I></A><A style="DISPLAY: none" class=delAttention href="#">取消<I class="\'l\'"></I></A></DIV></LI>
    <LI class="userList "><EM class=ico_num>11</EM> <EM class="ico_state "></EM><SPAN class=userPic><A title=经纬张颖(@经纬张颖) href="/matrixdavidzhang" rel=经纬张颖(@经纬张颖) 1333183314493="11" card="1" ctype="2"><IMG alt=经纬张颖(@经纬张颖) src="http://t0.qlogo.cn/mbloghead/d30b0807601b9a9dc36c/40"></A></SPAN><SPAN class=userName><A title=经纬张颖(@经纬张颖) href="/matrixdavidzhang" rel=经纬张颖(@经纬张颖) 1333183314493="61" card="1" ctype="2">经纬张颖</A></SPAN><SPAN class=topData>3487264</SPAN><SPAN class=pint>张颖,经纬中国创始人、分众传媒董事、新浪乐居董事。投...</SPAN> 
    <DIV class=attentBox><INPUT class=addAttention value="收听<i class=\'l\'></i>" type=button><A style="DISPLAY: none" class=delAttention href="http://t.qq.com/rank.php?id=5&amp;p=1#">取消<I class=l></I></A><A style="DISPLAY: none" class=delAttention href="#">取消<I class="\'l\'"></I></A></DIV></LI>A
     string pat = @"(?is)<LI\s*class=""userList\s*[^""]*"">.*?<SPAN\s*class=userPic><A\s*title=([^\(]+?)\([^""]+\)\s*href=""/([^""]*)""\s*[^>]*>.*?</A></SPAN>\s*<SPAN\s*class=topData>(.*?)</SPAN>";
                MatchCollection matches = Regex.Matches(input, pat);
                Dictionary<string, string> matchstr = new Dictionary<string, string>();
                List<string> topdata = new List<string>();
                foreach (Match match in matches)
                {
                    matchstr.Add(match.Groups[1].Value, match.Groups[2].Value);
                    topdata.Add(match.Groups[3].Value);
                }