我获取了一个html页面,里面有
<html><table>
<tr><td>dsfasdfasdfasdfsadfsadfas</td></tr>
</table><table>
<tr><td>
  <a href="detial.asp?id=83&type=嘿嘿">详细</a>
  <a href="detial.asp?id=84&type=嘿嘿">详细</a>
  <a href="detial.asp?id=85&type=嘿嘿">详细</a>
  <a href="detial.asp?id=86&type=嘿嘿">详细</a> </td>
</tr>
</table></html>我只获取到 "detial.asp?id=数字&type=嘿嘿"  这个地方添加到listbox里去就行了这个要怎么遍历还有写正规表达式

解决方案 »

  1.   

    Regex reg = new Regex(@"(?is)<a[^>]*?href=(['""]?)(?<url>[^'""\s>]+)\1[^>]*>(?<text>(?:(?!</?a\b).)*)</a>");
                MatchCollection mc = reg.Matches("");
                foreach (Match m in mc)
                {
                    Console.Write(m.Groups["url"].Value);
                }
      

  2.   

    除了正则表达式,还可以使用这个:
    假设你在webbrowser控件中访问了该页,然后可以这么获取:HtmlElement Submit;
    HtmlElementCollection hec = this.webBrowser1.Document.GetElementsByTagName("a");
    foreach (HtmlElement he in hec)
    {
        if (he.GetAttribute("href") == "detial.asp?id=数字&type=嘿嘿")
        {
            Submit = he;//找到按钮
            listbox.Add(he.InnerText);
            break;
        }
    }
      

  3.   

    取不到。   页面有非常多的 a 标记  我想要以这个开头 detial.asp?id=    以这个&type=嘿嘿结尾  中间是数字
      

  4.   

    html...可以看作XML的另一种表现形式....
      

  5.   


            private static void TestRegex03()
            {
                string html = @"<html><table>
    <tr><td>dsfasdfasdfasdfsadfsadfas</td></tr>
    </table><table>
    <tr><td>
      <a href=""detial.asp?id=83&type=嘿嘿"">详细</a>
      <a href=""detial.asp?id=84&type=嘿嘿"">详细</a>
      <a href=""detial.asp?id=85&type=嘿嘿"">详细</a>
      <a href=""detial.asp?id=86&type=嘿嘿"">详细</a> </td>
    </tr>
    </table></html>";
                MatchCollection mc = Regex.Matches(html, @"(?<=<a\s*href=(['""]?))[^ '""]+?(?=\1>)");
                foreach (Match m in mc)
                {
                    //m.Value就是你要的
                    Console.WriteLine(m.Value + " [位置在:" + m.Index.ToString() + "]");
                }
            }
      

  6.   

    添加列表
    Console.WriteLine(m.Value + " [位置在:" + m.Index.ToString() + "]");
    换为
    ListBox1.Items.Add(m.Value);
      

  7.   

    已经差不多了,,,,再帮我写一个正规表达式:
      <tr bgcolor="#FFFFFF" onMouseOver="this.style.backgroundColor='#999999'" onMouseOut="this.style.backgroundColor='#ffffff'" style="CURSOR: hand" title="--查看详细内容--" onClick="javascript:see('Detial.asp?id=36&type=嘿嘿')" >
    </tr>  <tr bgcolor="#FFFFFF" onMouseOver="this.style.backgroundColor='#999999'" onMouseOut="this.style.backgroundColor='#ffffff'" style="CURSOR: hand" title="--查看详细内容--" onClick="javascript:see('Detial.asp?id=26&type=嘿嘿')" >
    </tr>
      <tr bgcolor="#FFFFFF" onMouseOver="this.style.backgroundColor='#999999'" onMouseOut="this.style.backgroundColor='#ffffff'" style="CURSOR: hand" title="--查看详细内容--" onClick="javascript:see('Detial.asp?id=48&type=嘿嘿')" >
    </tr>
      <tr bgcolor="#FFFFFF" onMouseOver="this.style.backgroundColor='#999999'" onMouseOut="this.style.backgroundColor='#ffffff'" style="CURSOR: hand" title="--查看详细内容--" onClick="javascript:see('Detial.asp?id=40&type=嘿嘿')" >
    </tr>
    我只要获取    Detial.asp?id=数字&type=嘿嘿 上面 4个
      

  8.   

    MatchCollection mc = Regex.Matches(yourHtml,@"(?<=<tr.+?javascript:see\(')[^']+");
      

  9.   

    忽略大小写。
    MatchCollection mc = Regex.Matches(yourHtml,@"(?i)(?<=<tr.+?javascript:see\(')[^']+");
      

  10.   

    以上的方法都不行。页面还有其它的地址::<html><table>
    <tr><td>dsfasdfasdfasdfsadfsadfas</td></tr>
    </table><table>
    <tr><td>
      <a href="detial.asp?id=83&type=嘿嘿">详细</a>
      <a href="detial.asp?id=84&type=嘿嘿">详细</a>
      <a href="detial.asp?id=85&type=嘿嘿">详细</a>
      <a href="detial.asp?id=86&type=嘿嘿">详细</a> </td>
    </tr>
    </table></html>
    我只要获取html页面上的像这种地址---> detial.asp?id=83&type=嘿嘿  
                                          detial.asp?id=84&type=嘿嘿 
                                          detial.asp?id=85&type=嘿嘿  其它东西都不要的。
      

  11.   

    你贴的2次规则都不同。好吧。再猜测你的意思一次。
    MatchCollection mc = Regex.Match(yourHtml,@"(?is)detial.asp\?id=[^""']+");