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

Posted 多安分

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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"
onchange="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.

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

以上是关于asp.net爬虫asp.NET分页控件抓取第n页数据 javascript:__doPostBack的主要内容,如果未能解决你的问题,请参考以下文章

ASP.NET分页控件

asp.net分页控件使用详解附实例下载

ASP.NET 中如何用C#语言代码实现分页功能

asp.net中GridView怎样进行分页,编辑,删除操作

Asp.Net中的三种分页方式总结

ASP.NET使用ajax实现分页局部刷新页面