需求:如何取一个“页面”中的所有的
<a href="/property/view/6293/" class="property_title" target="_blank">
     新湖明珠城(一至三期)
</a>
相关数据?
要求:用c#正则取href中的6293和其中的值如:上面的结果应该是:6293、新湖明珠城(一至三期)

解决方案 »

  1.   

    再补充一点,只取含有class="property_title" 属性的a标签
      

  2.   

                string html = @"<a href=""/property/view/6293/"" class=""property_title"" target=""_blank"">
        新湖明珠城(一至三期)
    </a> ";            Regex reg = new Regex(@"(?is)<A\shref=""(.*?)""\sclass=""property_title"".*>([^>]+?)</A>");
                MatchCollection mc = reg.Matches(html);
                foreach (Match m in mc)
                {
                    Console.WriteLine("地址:"+ m.Groups[1].ToString() + " \r\n连接名:"+m.Groups[2].ToString() );
                }            /*
                 地址:/property/view/6293/
    连接名:
        新湖明珠城(一至三期)
                 */
      

  3.   

     string html = @"<a href=""/property/view/6293/"" class=""property_title"" target=""_blank"">
        新湖明珠城(一至三期)
    </a> ";            Regex reg = new Regex(@"(?is)<A\shref=""/.*/.*/(.*)/""\sclass=""property_title"".*>([^>]+?)</A>");
                MatchCollection mc = reg.Matches(html);
                foreach (Match m in mc)
                {
                    Console.WriteLine("地址:"+ m.Groups[1].ToString() + " \r\n连接名:"+m.Groups[2].ToString() );
                }            /*
                 地址:6293
    连接名:
        新湖明珠城(一至三期)
                 */
      

  4.   

    上面的正则从http://shanghai.souwoo.com/property/SO这个页面的源码中取不到全
      

  5.   

                Regex reg = new Regex(@"<a href=""/property/view/(\d+?)/"" class=""property_title"" target=""_blank"">([^>]+)</a>");
                MatchCollection mc = reg.Matches(pageHtml);
                foreach (Match m in mc)
                {
                    //Console.WriteLine(m.Groups[0].ToString());
                    Console.WriteLine("地址:" + m.Groups[1].ToString() + " 连接名:" + m.Groups[2].ToString()+"\r\n");
                }