想获取一个网站上所有栏目的链接该怎么做呢
,包括栏目下的相关栏目
请高手指点下谢谢

解决方案 »

  1.   

    private void button1_Click(object sender, EventArgs e)
            {
                for (int i = 0; i < webBrowser1.Document.Links.Count;i++ )
                {
                    string str = webBrowser1.Document.Links[i].OuterHtml;
                    int a1 = str.IndexOf("href=\"") + 6;
                    int a2 = str.LastIndexOf( "\" target");
                    listBox1.Items.Add(str.Substring(a1, a2-a1));               
                }            
            }
      

  2.   

    有html么可以正则匹配出所有的a
    或者用dom加载,然后拉出所有的超链接
      

  3.   

    用正则表达式匹配<a href=''></a>
      

  4.   

    抓取页面通过正则获取连接和文字
    System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(url); 
        request.UserAgent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022)"; 
        System.Net.WebResponse response = request.GetResponse(); 
        System.IO.Stream resStream = response.GetResponseStream(); 
        System.IO.StreamReader sr = new System.IO.StreamReader(resStream, encoding); 
        string html = (sr.ReadToEnd()); 
        resStream.Close(); 
        sr.Close(); 
    string strPattern=@"a[\s]+href=(? <Link>[^\s>]+)[^>]*>(? <Text>[^ <]*) </a>"; 
    MatchCollection Matches=Regex.Matches(html,strPattern,RegexOptions.IgnoreCase|RegexOptions.Compiled); 
                foreach(Match mc in Matches) 
                { 
                    Console.Write(mc.Groups["Link"].Value.ToString().Trim()); 
                    Console.Write(mc.Groups["Text"].Value.ToString().Trim()); 
                     
                }