数据采集之,采集AspNetPager1分页的页面

 private void button2_Click(object sender, EventArgs e)
        {  utility.Eventtarget = "AspNetPager1";  
            utility.Eventargument = "2";
            PrepareData();
            Post();
        }
        public void PrepareData()
        {
             string sHtml = utility. GetPageHTML("url");
            string sPattern = "id=///"__VIEWSTATE///"//svalue=///"(?<ViewState>[^>]*)///"";
            MatchCollection matchs = Regex.Matches(sHtml, sPattern, RegexOptions.IgnoreCase | RegexOptions.Singleline);
            if (matchs.Count == 0) return;
          utility.Viewstate =System.Web.HttpUtility.UrlEncode( matchs[0].Groups["ViewState"].Value);
          
        }
        public void Post()
        {
            string strId = "guest";
            string strPassword = "123456";

            ASCIIEncoding encoding = new ASCIIEncoding();
            string postData = "__EVENTTARGET=" + utility.Eventtarget;
            //postData += "&__VIEWSTATE=" + utility.Viewstate;
            postData += "&__EVENTARGUMENT=" + utility.Eventargument;
            //string postData = "userid=" + strId;
           // postData += ("&password=" + strPassword);

            byte[] data = encoding.GetBytes(postData);

            // Prepare web request...
            HttpWebRequest myRequest =
            (HttpWebRequest)WebRequest.Create("url");
            myRequest.AllowAutoRedirect = true;
            myRequest.Method = "POST";
            myRequest.ContentType = "application/x-www-form-urlencoded";
            myRequest.ContentLength = data.Length;
            Stream newStream = myRequest.GetRequestStream();

            // Send the data.
            newStream.Write(data, 0, data.Length);
            newStream.Close();

            // Get response
            HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
            StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);
            string content = reader.ReadToEnd();
            //Console.WriteLine(content);
            webBrowser1.DocumentText = content;
            webBrowser1.Refresh();
        }
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="CutPage.WebForm1" %> <%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <asp:Repeater ID="Repeater1" runat="server"> <HeaderTemplate> <table width="100%" border="1" cellspacing="0" cellpadding="4" style="border-collapse: collapse"> <tr style="background-color: #CCCCFF"> <th style="width: 10%">激活码</th> <th style="width: 5%">代理商ID</th> <th style="width: 5%">员工ID</th> <th style="width: 5%">激活数量</th> <th style="width: 10%">开始时间</th> <th style="width: 10%">结束时间</th> <th style="width: 20%">公司名称</th> <th style="width: 20%">公司地址</th> <th style="width: 15%">联系电话</th> </tr> </HeaderTemplate> <ItemTemplate> <tr style="background-color: #FAF3DC"> <td><%#DataBinder.Eval(Container.DataItem,"Activation")%></td> <td><%#DataBinder.Eval(Container.DataItem, "DealerId")%></td> <td><%#DataBinder.Eval(Container.DataItem, "UserId")%></td> <td><%#DataBinder.Eval(Container.DataItem, "Quantity")%></td> <td><%#DataBinder.Eval(Container.DataItem, "StartTime")%></td> <td><%#DataBinder.Eval(Container.DataItem, "EndTime")%></td> <td><%#DataBinder.Eval(Container.DataItem, "CompanyName")%></td> <td><%#DataBinder.Eval(Container.DataItem, "CompanyAddress")%></td> <td><%#DataBinder.Eval(Container.DataItem, "CompanyContact")%></td> </tr> </ItemTemplate> <FooterTemplate> </table> </FooterTemplate> </asp:Repeater> <webdiyer:aspnetpager id="AspNetPager1" runat="server" onpagechanged="AspNetPager1_PageChanged" currentpagebuttonposition="Center" custominfohtml="第%CurrentPageIndex%页,共%PageCount%页,每页%PageSize%条" firstpagetext="首页" lastpagetext="尾页" layouttype="Table" nextpagetext="下一页" pageindexboxtype="DropDownList" pagingbuttonlayouttype="Span" prevpagetext="上一页" showcustominfosection="Left" submitbuttontext="Go" textafterpageindexbox="页" textbeforepageindexbox="转到"> </webdiyer:aspnetpager> </form> </body> </html>

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值