Bootstrap

【asp.net爬虫】asp.NET分页控件抓取第n页数据 javascript:__doPostBack

最近在模拟HTTP请求抓取数据,但是服务器是asp.net开发的

分页控件代码

    <tr>
        <td align="left">共&nbsp210&nbsp条记录&nbsp--&nbsp第&nbsp2&nbsp页&nbsp--&nbsp共&nbsp3&nbsp页</td><td align="right"><a id="OraclePager1_First" 
href="javascript:__doPostBack(&#39;OraclePager1$First&#39;,&#39;&#39;)"> 首页 </a>&nbsp;<a id="OraclePager1_Prev" href="javascript:__doPostBack(&#39;OraclePager1$Prev&#39;,&#39;&#39;)"> 上一页
</a>&nbsp;<a id="OraclePager1_Next" href="javascript:__doPostBack(&#39;OraclePager1$Next&#39;,&#39;&#39;)"> 下一页 </a>&nbsp;<a id="OraclePager1_Last"
href="javascript:__doPostBack(&#39;OraclePager1$Last&#39;,&#39;&#39;)"> 尾页 </a><select name="OraclePager1$PageList"
οnchange="javascript:setTimeout(&#39;__doPostBack(\&#39;OraclePager1$PageList\&#39;,\&#39;\&#39;)&#39;, 0)" id="OraclePager1_PageList"> <option value="0">1</option> <option selected="selected" value="1">2</option> <option value="2">3</option> </select></td> </tr>

点击下一页其实是调用js方法

javascript:__doPostBack(&#39;OraclePager1$Next&#39;,&#39;&#39;)

通过抓包拼接请求postdata

                ticket_postdata = "__EVENTTARGET=OraclePager1%24Next&__EVENTARGUMENT=" + getElementValueByID(ticket_html, "__EVENTARGUMENT") + "&__LASTFOCUS=&__VIEWSTATE=" + getElementValueByID(ticket_html, "__VIEWSTATE") + "&__VIEWSTATEGENERATOR=" + getElementValueByID(ticket_html, "__VIEWSTATEGENERATOR") + "&__VIEWSTATEENCRYPTED=&" + getElementValueByID(ticket_html, "__VIEWSTATEENCRYPTED") + "&txtMemberCardNO=16881270&txtMemberName=&txtStartData=2016-12-01&txtStartTime=00%3A00%3A00&txtEndData=2016-12-29&txtEndTime=23%3A59%3A59&txtPNR=&txtOperatorName=&txtFlight=&txtAirLine=&txtGuestName=&txtGuestCardNo=&txtOrderID=&ddlOrderStatus=&ddlOrderSource=&ddlactivecode=0&txtMobile=&txtTicketNo=&txtKXOrderId=&ddlPayType=2&ddlOrderType=0&OraclePager1%24PageList=" + count;
                ticket_html = spider.POST(main_url + "Ticket/Ticket/TicketOrderList.aspx?TopMenuID=3&LeftMenuID=306", ticket_postdata, main_url + "Ticket/Ticket/TicketOrderList.aspx?TopMenuID=3&LeftMenuID=306", Encoding.GetEncoding("GB2312"));

结果服务器返回

Invalid postback or callback argument. Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page. 
For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected,
use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.

坑爹的,根本获取不到想要的第二页数据

;