我用webrequest可以把整个页面内容获取下来后,我想获取指定标签里面的数据,
(如 <div="top">开始到</div>结束之间的数据),
我想到的办法是把整个页面数据赋值给string后,然后indexOf去截取,或者复制给xml后再去获取指定标签内容,除了这两种办法,还有其他更好的方法吗?新手,请大家帮帮忙,谢谢了...webrequest 页面指定标签

解决方案 »

  1.   

    像这样:<div=\"top\">(?:.|[\r\n])*?</div>
      

  2.   

    正则匹配string获取到的页面数据吗?
      

  3.   

    Regex Div = new Regex("<div=\"top\">(?:.|[\r\n])*?</div>", RegexOptions.ExplicitCapture | RegexOptions.Multiline | RegexOptions.IgnoreCase);
    Match match = Div.Match(页面内容(string));
    string divs= match.ToString(); divs应该就是你想要的
      

  4.   

    这是页面只有一个div标签的情况
      

  5.   

    那就这样取:
     MatchCollection mCollection = Div.Matches(页面内容(string));
     foreach (Match match in mCollection)
    {}