i need to access the detailed search result page using curl, but for some reason i am not able to do so... Please help!

The site is www.justdial.com and i am searching for a* ... on the very first page there is a listing from banglore... i want to be able to access that using curl...

Thanx.

Member Avatar for diafol

What code are you using so far? Post your attempt and someone will help you with it.

<?
set_time_limit(0);
//set curl
$ch = curl_init();
$ckfile = "tmp/cookie.txt";
curl_setopt ($ch, CURLOPT_COOKIEJAR, $ckfile);
curl_setopt ($ch, CURLOPT_COOKIEFILE, $ckfile);
curl_setopt($ch, CURLOPT_URL,'http://search.justdial.com/');
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
$result=curl_exec ($ch);
curl_setopt ($ch, CURLOPT_COOKIEJAR, $ckfile);
curl_setopt ($ch, CURLOPT_COOKIEFILE, $ckfile);
curl_setopt($ch, CURLOPT_URL,'http://search.justdial.com/srch/all_indiasrch/all_india.php?page=1&companyname=a*&Allcity=All+India+Search');
curl_setopt($ch, CURLOPT_HTTPHEADERS,array('Host: search.justdial.com','Referer: http://search.justdial.com/srch/all_indiasrch/all_india.php')); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
$result=curl_exec ($ch);
preg_match('/\>([0-9].*?) Results for/',$result,$cnt);
$pages=$cnt[1];
preg_match_all('/javascript:showdetails_allindia\(\'([\s\S\w\W].*?)\',\'([\s\w\S\W].*?)\',\'sms\'\)/',$result,$details);
$i=0;
//foreach($details[1] as $i=>$v)
	{
	//post data to details page...
	curl_setopt ($ch, CURLOPT_COOKIEJAR, $ckfile);
	curl_setopt ($ch, CURLOPT_COOKIEFILE, $ckfile);
	curl_setopt($ch, CURLOPT_URL,'http://search.justdial.com/srch/search_cmd.php?srch=true&sms=undefined&city='.$details[2][$i].'&define=+&value=');
	curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
	curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
	curl_setopt($ch, CURLOPT_COOKIE, 'CITY='.$details[2][$i].'; ShowCity=;');
	curl_setopt($ch, CURLOPT_HTTPHEADERS,array('Host: search.justdial.com','Referer: http://search.justdial.com/srch/all_indiasrch/all_india.php?page=1&companyname=a*&Allcity=All+India+Search')); 
	curl_setopt($ch, CURLOPT_POST, 1);
	curl_setopt($ch, CURLOPT_HEADER, TRUE);
	curl_setopt($ch, CURLOPT_POSTFIELDS,'city='.$details[2][$i].'&searchtype=&Stype=company&docId='.$details[1][$i].'&AllIndiaSearch=true&intermid='); 
	$result=curl_exec ($ch);
	echo $result;
	}
curl_close ($ch);
?>
Member Avatar for diafol

http:// search.justdial.com/srch/all_indiasrch/all_india.php?page=1&companyname=a*&Allcity=All+India+Search

doesn't exist - the a* comes via form so it won't be recognised by $_GET.
From what I can see the search form under All cities in India can be stripped to the following:

<FORM METHOD='POST' name='justDial' action='search/search.php?srch=true' >
	<INPUT TYPE="hidden" NAME="area" value="">
	<input id='txt2' type="text" readonly='1' name="city" value="All India Search" />
	<input type='radio' name='Stype' value='category' CHECKED >
	[B]<input type="text" id='txt1_cat' name="q" value="" autocomplete='off' >[/B] 
	<INPUT TYPE='submit' NAME='GO' VALUE='GO' ONCLICK="return Go_AllIndiaSearch('yes');">
	<INPUT TYPE="hidden" NAME="sub" value=''>
	<INPUT TYPE="hidden" NAME="result">
	<INPUT TYPE="hidden" NAME="inter">
	<INPUT TYPE="hidden" NAME="login_name">
	<INPUT TYPE="hidden" NAME="login_pass">
	<input type='hidden' name='img_forget'>
	<input type='hidden' name='screen_name'>
	<input type='hidden' name='login_name1'>
	<input type='hidden' name='login_pass1'>
	<INPUT TYPE="hidden" NAME="Allsearchtype">
	<INPUT TYPE="hidden" NAME="Allcity">
	<INPUT TYPE="hidden" NAME="AllIndiaSearch">
</FORM>

I assume the 'txt1_cat' field takes the "a*".

You probably got this far yourself, sorry, but I ain't got time to look further.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.