【asp.net爬虫】asp.NET分页控件抓取第n页数据 javascript:__doPostBack
最近在模拟HTTP请求抓取数据,但是服务器是asp.net开发的
分页控件代码
<tr> <td align="left">共 210 条记录 -- 第 2 页 -- 共 3 页</td><td align="right"><a id="OraclePager1_First"
href="javascript:__doPostBack('OraclePager1$First','')"> 首页 </a> <a id="OraclePager1_Prev" href="javascript:__doPostBack('OraclePager1$Prev','')"> 上一页
</a> <a id="OraclePager1_Next" href="javascript:__doPostBack('OraclePager1$Next','')"> 下一页 </a> <a id="OraclePager1_Last"
href="javascript:__doPostBack('OraclePager1$Last','')"> 尾页 </a><select name="OraclePager1$PageList"
onchange="javascript:setTimeout('__doPostBack(\'OraclePager1$PageList\',\'\')', 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('OraclePager1$Next','')
通过抓包拼接请求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.
坑爹的,根本获取不到想要的第二页数据