问题主旨:技术交流需求:用一句表达式,就能匹配出网站上所有的链接,即匹配出url地址和标题。
例如:网页中有
……<a href='a.htm>abc</a>……匹配后得到的结果:
链接: a.htm
标题:abc请以www.sina.com.cn或news.sina.com.cn网站为例。
运行你的程序后,就能取出网站上可以抓取得到的所有链接。如果你是牛人,就请用你的牛刀!杀头大牛,给大家看。

解决方案 »

  1.   

    <a[\s\S]*?href=("(?<href>[^"]*)"|'(?<href>[^']*)'|(?<href>[^>\s]*))[^>]*?>(?<title>[\s\S]*?)</a>public static Regex regex = new Regex(
        @"<a[\s\S]*?href=(""(?<href>[^""]*)""|'(?<href>[^']*)'|(?<href"
        + @">[^>\s]*))[^>]*?>(?<title>[\s\S]*?)</a>",
        RegexOptions.IgnoreCase | RegexOptions.Compiled);
    两个html页面放在一起,一共匹配了2416个,而</a>一共有2417个,不知道落下了哪一个^_^
      

  2.   

    Expression:   <a[\s]+[^>]*?href[\s]?=[\s\"\']+(.*?)[\"\']+.*?>([^<]+|.*?)?<\/a>  
    Description:  This regex will extract the link and the link title for every a href in HTML source. Useful for crawling sites. Note that this pattern will also allow for links that are spread over multiple lines.
    Matches:  [<a href='http://www.regexlib.com'>Text</a>], [<a href="...">Text</a>] 
    Non-Matches:  [all other html tags]
      

  3.   

    fancyf(凡瑞) 老兄,用你的那个表达式,我这面没有匹配到你所说的那么多的。
      

  4.   

    楼上不厚道
    发现fancyf(凡瑞)好有空啊呵呵~~
    好像我每次来都看得到
      

  5.   

    to sharkshi(sharkshi):
    典型的水土不服^_^
      

  6.   

    珍藏一下,以后用得着!
    fancyf(凡瑞)老哥,怎还不睡呢?
      

  7.   

    to  fancyf(凡瑞) 兄弟
    能否把你测试的源码给我测试一下,我这面不知是什么原因,匹配出来的东西,很少。
      

  8.   

    fancyf(凡瑞) 真是牛,你正则我匹配出来了。牛人就是牛!