使用php获取asp.net网站数据

时间:2017-05-09 11:07:38

标签: php web-scraping screen-scraping

我正试图从asp.net网站获取数据,但由于查看状态隐藏字段,我无法抓住它。

我需要根据所选的下拉菜单获取数据,最后输出将生成我想要获取这些数据。

传递视图状态和我从我身边创建的每个隐藏字段,并使用jquery将数据存储到我的字段中,然后我使用curl传递这些数据。

但最后我得到了像

这样的错误
"nvalid 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."

mycode的

<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.2.1.min.js"></script>

<form method="post">
    __VIEWSTATE : <textarea name="txtstate" id="txtstate"></textarea>
  __EVENTTARGET : <textarea name="txteventtarget" id="txteventtarget"></textarea>
  __EVENTARGUMENT : <textarea name="txteventargument" id="txteventargument"></textarea>
  __LASTFOCUS : <textarea name="txtlostfocus" id="txtlostfocus"></textarea>
  __VIEWSTATEENCRYPTED : <textarea name="txteventencrypted" id="txteventencrypted"></textarea>
  __EVENTVALIDATION :  <textarea name="txteventvalidation" id="txteventvalidation"></textarea>
    <input type="submit" name="btnsubmit" value="SUBMIT" />
</form>
<?php 
if(isset($_REQUEST['btnsubmit'])){
  $h = curl_init();
  curl_setopt($h, CURLOPT_URL, "http://xlnindia.gov.in/SOS/xln_regd_pharma_vacancy.aspx?ST=PB"); 
  curl_setopt($h, CURLOPT_POST, true);
  $fields = array(
  'ST' => 'GJ',
  'ddldistrict' => 'AMR',
  'ddltaluka' => '',
  'btnSearch' => 'Search',
  'ddlcrit' => '',
  '__VIEWSTATE' => $_REQUEST['txtstate'],
  '__EVENTTARGET' => $_REQUEST['txteventtarget'],
  '__EVENTARGUMENT' => $_REQUEST['txteventargument'],
  '__LASTFOCUS' => $_REQUEST['txtlostfocus'],
  '__VIEWSTATEENCRYPTED' => $_REQUEST['txteventencrypted'],
  '__EVENTVALIDATION' => $_REQUEST['txteventvalidation']
  );
  $fields_string = http_build_query($fields);

  curl_setopt($h, CURLOPT_POSTFIELDS,$fields_string);
  curl_setopt($h, CURLOPT_HEADER, false);
  curl_setopt($h, CURLOPT_RETURNTRANSFER, 1);

  $result = curl_exec($h);
  echo $result;
}else{
    $h = curl_init();
  curl_setopt($h, CURLOPT_URL, "http://xlnindia.gov.in/SOS/xln_regd_pharma_vacancy.aspx?ST=PB"); 
  curl_setopt($h, CURLOPT_HEADER, false);
  curl_setopt($h, CURLOPT_RETURNTRANSFER, 1);

  $result = curl_exec($h);
  echo $result;
}
?>


<script>
$(document).ready(function(){
    $("#txtstate").val($('#__VIEWSTATE').val());
      $("#txteventargument").val($('#__EVENTTARGET').val());
    $("#__EVENTARGUMENT1").val($('#__EVENTARGUMENT').val());
    $("#txtlostfocus").val($('#__LASTFOCUS').val());
    $("#txteventencrypted").val($('#__VIEWSTATEENCRYPTED').val());
    $("#txteventvalidation").val($('#__EVENTVALIDATION').val());
});
</script>

0 个答案:

没有答案