数据采集,微软控件分页问题的处理

            System.Net.WebClient WebClientObj = new System.Net.WebClient();
                System.Collections.Specialized.NameValueCollection PostVars = new System.Collections.Specialized.NameValueCollection();
                PostVars.Add("__VIEWSTATE", _viewstate);
                PostVars.Add("__EVENTVALIDATION", _eventvalidation);
                PostVars.Add("__EVENTTARGET", "lnkNext");
                PostVars.Add("__EVENTARGUMENT", "");
                PostVars.Add("Toshow", "1");
                PostVars.Add("txtPage", "");
                WebClientObj.Headers.Add("ContentType", "application/x-www-form-urlencoded");
                try
                {
                    byte[] byte1 = WebClientObj.UploadValues(urlStr, "POST", PostVars);
                    string ResponseStr = Encoding.UTF8.GetString(byte1); //得到当前页面对应的html 文本字符串
                    GetPostValue(ResponseStr);//得到当前页面对应的 __VIEWSTATE 等上面需要的信息,为抓取下一页面使用
                    SaveMessage(ResponseStr);//保存自己内容到数据库中
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }

       PostVars.Add("__VIEWSTATE", _viewstate);
                PostVars.Add("__EVENTVALIDATION", _eventvalidation);
                PostVars.Add("__EVENTTARGET", "lnkNext");
                PostVars.Add("__EVENTARGUMENT", "");
                PostVars.Add("Toshow", "1");
                PostVars.Add("txtPage", "");

 

注意:用火狐浏览器“网络”查看需要POST的参数.

posted on 2012-05-17 18:52  张扬个性,敢为天下先  阅读(631)  评论(0编辑  收藏  举报