假如页面上有很多<li><a href="" ></a></li> 我想获得页面上所有<li><a href="" ></a></li> 对于href里面的地址。我改怎么写, 

解决方案 »

  1.   

    1.利用HttpWebResponse或者WebClient得到网页源码
    2.利用正则或者HtmlDocument分析源码
    正则就是:(?i)<a[^>]*?href=(['""]?)(?<href>[^'""]*?)\1[^>]*?>
    取分组m.Groups["href"].value
      

  2.   

    用HtmlAgilityPack解析抓取到的网页源码,取出所有的a元素,获取其href属性的值就行了。
    取出所有的a元素的xpath表达式为://a示例:输出博客园首页所有超链接的地址。
    HttpWebRequest httpWebRequest = WebRequest.Create(@"http://www.cnblogs.com") as HttpWebRequest;
    HttpWebResponse httpWebResponse = httpWebRequest.GetResponse() as HttpWebResponse;
    Stream stream = httpWebResponse.GetResponseStream();
    StreamReader reader = new StreamReader(stream, Encoding.UTF8);
    string s = reader.ReadToEnd();
    reader.Close();
    httpWebResponse.Close();
    HtmlDocument htmlDoc = new HtmlDocument();
    htmlDoc.LoadHtml(s);
    HtmlNodeCollection anchors = htmlDoc.DocumentNode.SelectNodes(@"//a");
    foreach (HtmlNode anchor in anchors)
    Response.Write(anchor.Attributes["href"].Value + "<br/>");
      

  3.   

    抓去这些我都知道。 主要就是这个正则怎么写 我要herf里面包含一个某个单词的 只要取到href里面数据
      

  4.   

    还一个问题是 假如我要取某个标签里面的数据改怎么写。 比如title里面的数据 又或者是定义在页面上面js一个参数  比如 aaa="bbb" 我要取aaa 对于的这个bbb正则怎么写
      

  5.   

    string key = textBox1.Text;  //aaa
    Regex reg = new Regex(Regex.Escape(key) + @"=(['""]?)(?<value>[^'""\s>]*)\1");
    MatchCollection mc = reg.Matches(yourStr);
    foreach (Match m in mc)
    {
        richTextBox2.Text += m.Groups["value"].Value + "\n";  //bbb
    }
      

  6.   

    前台的话可以用JQUERY读取 
    $("ul li a").each(function(){   alert($(this).attr("href"))
    })
      

  7.   

    我不是要得到textbox的value 我是想得到某个div里面的数据。
      

  8.   


    你要通过aaa取bbb,那么aaa就应该是个变量,这里只是举例从textbox取这个变量而已
    拜托找本基础的书看看先