首页 > 代码库 > 【asp.net爬虫】asp.NET分页控件抓取第n页数据 javascript:__doPostBack
【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=http://www.mamicode.com/"javascript:__doPostBack('OraclePager1$First','')"> 首页 </a> <a id="OraclePager1_Prev" href=http://www.mamicode.com/"javascript:__doPostBack('OraclePager1$Prev','')"> 上一页
</a> <a id="OraclePager1_Next" href=http://www.mamicode.com/"javascript:__doPostBack('OraclePager1$Next','')"> 下一页 </a> <a id="OraclePager1_Last"
href=http://www.mamicode.com/"javascript:__doPostBack('OraclePager1$Last','')"> 尾页 </a><select name="OraclePager1$PageList"
onchange="javascript:setTimeout('__doPostBack(\'OraclePager1$PageList\',\'\')', 0)" id="OraclePager1_PageList"> <option value=http://www.mamicode.com/"0">1</option> <option selected="selected" value=http://www.mamicode.com/"1">2</option> <option value=http://www.mamicode.com/"2">3</option> </select></td> </tr>
点击下一页其实是调用js方法
javascript:__doPostBack('OraclePager1$Next','')
通过抓包拼接请求postdata
ticket_postdata = http://www.mamicode.com/"__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=http://www.mamicode.com/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
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。