<a href='/a/gongyi/2011/0625/8286.html' class='tt'preview/a>

                        <a href="/a/gongyi/2011/0625/8286.html" class="title">红十字蓝天救援队社会心理培训班在京举办</a><span class="info"><small>-- </small>06-25</span>
</li><li>
       <a href='/a/gongyi/2011/0625/8285.html' class='tt'preview/a>

                        <a href="/a/gongyi/2011/0625/8285.html" class="title">担心NBA停摆 姚明纳什慈善篮球赛搁浅</a><span class="info"><small>-- </small>06-25</span>
</li><li>
       <a href='/a/gongyi/2011/0625/8284.html' class='tt'preview/a>

                        <a href="/a/gongyi/2011/0625/8284.html" class="title">倪萍:慈善事业是艺人应该做的事情</a><span class="info"><small>-- </small>06-25</span>
</li><li>
       <a href='/a/gongyi/2011/0625/8283.html' class='tt'preview/a>

                        <a href="/a/gongyi/2011/0625/8283.html" class="title">斯凯孚助中国青少年参加哥德堡杯足球锦标赛</a><span class="info"><small>-- </small>06-25</span>
</li><li>
       <a href='/a/gongyi/2011/0625/8282.html' class='tt'preview/a>

                        <a href="/a/gongyi/2011/0625/8282.html" class="title">第六届中华慈善奖评委会召开 通过表彰名单</a><span class="info"><small>-- </small>06-25</span>
</li><li>
       <a href='/a/gongyi/2011/0624/8194.html' class='tt'preview/a>

                        <a href="/a/gongyi/2011/0624/8194.html" class="title">中国绿化基金会——幸福家园西部绿化行动</a><span class="info"><small>-- </small>06-24</span>
</li><li>
       <a href='/a/gongyi/2011/0624/8193.html' class='tt'preview/a>

                        <a href="/a/gongyi/2011/0624/8193.html" class="title">民间组织启动“清汞行动”</a><span class="info"><small>-- </small>06-24</span>
</li><li>
       <a href='/a/gongyi/2011/0624/8192.html' class='tt'preview/a>

                        <a href="/a/gongyi/2011/0624/8192.html" class="title">甘肃慈善总会1200万建14个敬老院</a><span class="info"><small>-- </small>06-24</span>
</li><li>
       <a href='/a/gongyi/2011/0624/8191.html' class='tt'preview/a>
上面一段 在网上采集的代码
 string str= @"<a href='\S+' class='tt'preview/a>";
        string[] href;
        Regex Reg = new Regex(str, RegexOptions.IgnoreCase);
        Match m = Reg.Match(text);//从最后一个“/”开始匹配
        if (m.Success)//匹配成功
        {
            href = new string[m.Groups.Count];
            for (int i = 0; i < href.Length; i++)
            {
                href[i] = m.Groups[i].ToString();
            }
        }
        else
        {
            href = new string[0];
        }我要取出里面的连接 可是我怎么也匹配不出来 还有  我要做采集 可是 有没有更好的方法 把采集出来的 列表中的 连接取出来 还有还有 连接取出来了之后 有的网站带HTTP 有的就是个/+连接  有的则是单纯的连接我怎么才能把网页真正的网址取出来呢

解决方案 »

  1.   


    //帖出你需要的结果Regex re = new Regex("(?<=<a\\s*href=\\\").*?(?=\\\"\\s*class=\\\"title\\\">)", RegexOptions.None);
    MatchCollection mc = re.Matches("text");
    foreach (Match ma in mc)
    {
      //ma.Value就是链接
    }
      

  2.   

    (?i)<a[^>]*href=(['"\s])?(?<href>[^'"\s]+)\1[^>]*class=(['"\s])tt\2preview/a>
      

  3.   

       RegexOptions.None 这个参数是什么意思?
      

  4.   

    至于完整的url,你只要随便打开一个链接就可以看到,把公共部分取出来,再添加到List的各个元素里就可以了            string html = "html内容";
                List<string> url = new List<string>();
                MatchCollection matches = Regex.Matches(html, @"<a\s*?href='([^']*?)'[^>]*?>", RegexOptions.IgnoreCase);
                if(matches.Count>=1)
                {
                    foreach (Match match in matches)
                    {
                        url.Add(match.Groups[1].Value);
                    }
                }