Hi all.
I'm tryng to scrape an internal website at my work that was wrote by someone in .aspx
When I try and scrape the page with cURL, it wont set the values on the form. it just reloads the page. I'm expecting it to set the values that I told it with the POST variables.
I wrote an example on an external site that I found that also uses .aspx. I think this could be any random site wrote in .aspx.
I'm hoping someone has been able to do this before or can figure out why cURL post variables dont work on a .aspx site.
here's a script that loads a page. saves the viewstate variable. then reloads the page and tries setting a form var. but it doesnt. why?
<?php
$cookie_file_path = "cookies/cookiejar.txt"; // Please set your Cookie File path
$fp = fopen("$cookie_file_path","w") or die("<BR><B>Unable to open cookie file $mycookiefile for write!<BR>");
fclose($fp);
$ch = curl_init();
$url ="http://www.rebac.net/MembershipDirectorySearch.aspx";
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
$result = curl_exec ($ch);
$token = "__VIEWSTATE";
$result = strstr($result, $token);
$result = substr($result, strlen($token));
$endpos = strpos($result, '" />');
$result = substr($result, 9,$endpos-4);
$postoptions = "__VIEWSTATE=$result&DropDownListSearchNationalState=MI";
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$postfields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
$result = curl_exec ($ch);
echo $result;
curl_close ($ch);
?>