首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

哪位高手有在winform中用webBrowers控件抓取网页页面的例子或代码

2013-07-08 
谁有在winform中用webBrowers控件抓取网页页面的例子或代码初次接触...希望给几个例子WinForm控件webwebbr

谁有在winform中用webBrowers控件抓取网页页面的例子或代码
初次接触...希望给几个例子 WinForm 控件 web webbrowers
[解决办法]
webBrowser控件操作动态html 

哈哈 为了今天,我几年前就特地准备好了代码示例了,今天终于用到了,赶快去我的资源里下载区吧。
[解决办法]
1.抓取页面源码,webbroser,webclient,WebRequest 等等
2.分析源码,利用正则或者DOM对象找到所需数据

 string url = "http://news.sina.com.cn/china/ ";//要获取的页面地址
                WebRequest req = WebRequest.Create(url);
                using (WebResponse res = req.GetResponse())    // GetResponse blocks until the response arrives
                {
                    using (Stream ReceiveStream = res.GetResponseStream())    // Read the stream into a string
                    {
                        StreamReader sr = new StreamReader(ReceiveStream);
                        string resultstring = sr.ReadToEnd();
                        var list = Regex.Matches(resultstring, @"(?i)<a[^>]*?href=(['""]?)(?<Url>[^'""]*?/(\d+?)\.shtml)\1[^>]*?>(?<Text>[^<>]*?)</a>").OfType<Match>().Select(a=>a.Groups["Url"].Value).ToList();
                        /*
                                 [0]    "http://news.sina.com.cn/c/2013-06-26/150027504392.shtml"    string


                                [1]    "http://news.sina.com.cn/c/2013-06-26/150027504392.shtml"    string
                                [2]    "http://news.sina.com.cn/c/2013-06-26/180027505390.shtml"    string
                                [3]    "http://news.sina.com.cn/c/2013-06-27/023927507832.shtml"    string
                         *       .
                         *       .
                         *       .
                         *       .
  
                         */
                    }
                }

热点排行