日期:2014-05-17  浏览次数:20773 次

C#(正则表达式筛选网页指定数据)
http://we.sportscn.com/viewnews-1415234.html我要筛选到这个网址上面的这一块内容的HTML源码,求正则表达式呀???xpath也可以...求高手帮忙呀感激不尽!

------解决方案--------------------
支持一下吧。我也希望学习一下了。
------解决方案--------------------
xPath就是Xml的形式截取 另外你采集下来的是html还是???
个人感觉 你应该直接采集他的html  否则你也要吧<br/>转成\r\n
------解决方案--------------------

<UL class=title>([\s\S]+?)<div id="ad4" class="ad4" style="display:none;">

------解决方案--------------------
取group[1]中的值
------解决方案--------------------

楼上的编码你弄错了.是gbk
------解决方案--------------------
正则中的 ' " 不要乱改.......................................................................................................................................................................................谁说了 ' " 在正则里面是一样的..
------解决方案--------------------
引用:

不行呀,求具体的源码呀把分都给他


我都贴出源码了.自己转换下就行了. 
@ 符号不要乱加呀.

 WebClient wc = new WebClient();
            wc.Encoding = System.Text.Encoding.GetEncoding("GBK");
            string str = wc.DownloadString("http://we.sportscn.com/viewnews-1415234.html");
            MatchCollection mc = Regex.Matches(str, "<UL class=title>([\\s\\S]+?)<div id=\"ad4\" class=\"ad4\" style=\"display:none;\">");
            foreach (Match item in mc)
            {
                Console.WriteLine(item.Groups[1].Value);
            }