Hi,
I am trying to get search result("Reg.nr:" field on the left menu) from this site, using curl method
Site Url: http://nbk2.autodata.no/
To get the search result actually the user need to login with the site, the login is working properly with the curl function.
The actual problem is that I tried passing the parameters through url like the same way as in the actual site but unfortunately
I am not getting the result, like in the actual site.
Following is the code for login and search, that I had used for this.And I also placed the login username password and also the search text(in the search
function url)in the code, could you please check it and let me know.
/* code to login to the site*/
$loginurl = "http://www.norskbildelkatalog.no/default.aspx?cat=2&Id=18";
$userName = "vwx7a"; //value of username
$userPwd = "smwhe"; //value of password field
$loginButton = ""; //value of login button
$userfieldname = "ctl00%24tbUserName"; //name of the field username
$passfieldname = "ctl00%24tbPassword"; //name of the field password
$buttonName = "ctl00%24btnLogin"; //name of the submit button
//$spiderId = $LoginDetails['idSpiders']; //end values
$link = "Startsiden";
$cookie_file_path = "cook.txt";
$agent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.7) Gecko/20070914 Firefox/2.0.0.7";
$reffer = "http://www.norskbildelkatalog.no";
$baseUrl = "http://nbk2.autodata.no";
$ch = curl_init('http://www.norskbildelkatalog.no/default.aspx?cat=2&Id=18');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
$password = '&' .$passfieldname.'=';
curl_setopt($ch, CURLOPT_POSTFIELDS, $userfieldname.'='. $userName . $password. $userPwd . '&'.$buttonName.'='. $loginButton.'&'.'__VIEWSTATE=%2FwEPDwULLTE2OTYxMTQyOTJkZKnDWEWkr2o2KzEZL%2FUtwkVYytbh&__EVENTVALIDATION=%2FwEWBAKCiZ7KBAL06sf%2FAQK%2F0oqcCQLnrI%2BZD94ytl4m3yVK2AjSmUM%2FlJpk24m3&');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);// allow redirects
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.1; ru; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5');
curl_setopt($ch, CURLOPT_COOKIEJAR, './cook.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, './cook.txt');
$result = curl_exec($ch);
//parse the html into a DOMDocument
$dom = new DOMDocument();
@$dom->loadHTML($result);
// grab all the on the page
$xpath = new DOMXPath($dom);
$hrefs = $xpath->query('/html/body//a');
for ($i = 0; $i < $hrefs->length; $i++) {
$href = $hrefs->item($i);
$url = $href->getAttribute('href');
$t = $href->nodeValue;
if(trim($t) != ""){
$arr[$i.$t] = $url;
}
//here we get the url and link value from the link name
if($t == $linkn){
echo $searchUrl = $baseUrl.$url;
echo $searchRes = Search($searchUrl);
exit;
}
}
/* code to search in the site*/
function Search($baseurl){
$loginurl = $baseurl;
$link = "VW";
$cookie_file_path = "/cook.txt";
$agent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.7) Gecko/20070914 Firefox/2.0.0.7";
$reffer = $baseurl;
$POSTFIELDS = 'tp_articlesearch_pnl_search_vehicle_criterion=1&tp_articlesearch%24input_search_single=AA52844&tp_articlesearch%24btn_search_single=tp_articlesearch_btn_search_single&__EVENTTARGET=&__EVENTARGUMENT=&__VIEWSTATE=%2FwEPDwUJOTEyNTM2NDY2ZGReJw3PG62XkgM7gYqdrdP%2B0zHxDQ%3D%3D&username=vwx7a&password=smwhe&login=Send&__PREVIOUSPAGE=oL0kSGhtXbLqdHQg0uFgqg2';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$loginurl);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
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_REFERER, $reffer);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
$result = curl_exec ($ch);
return $result;
curl_close ($ch);
}
/* Search end here */
YOu can see this sample code in the url: http://autobutler.no/test123.php