I'm trying to scrape data from scroogle using PHP curl library. I do not get results, but I get message:
"Sorry, but we are unable to provide results from Google"
Need your advice on how to correct my curl requests to imitate the same form as on [login to view URL]
See PHP code details below....
## Deliverables
Here is my PHP code:
function doPostRequest($url, $postData, $http_header = null)
{
$session = curl_init($url);
$options = array(
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $postData,
CURLOPT_HEADER => false,
CURLOPT_RETURNTRANSFER => true
);
curl_setopt_array($session, $options);
if (!is_null($http_header))
curl_setopt($session, CURLOPT_HTTPHEADER, $http_header);
$response = curl_exec($session);
curl_close($session);
return $response;
}
class ScroogleParser {
var $url = '[login to view URL]';
// Parses Scroogle search results;
// $num - number of results to get, up to 100
function parse($keywords, $num)
{
if ($num > 0 && $num <= 20)
$n = 2;
elseif($num <= 50)
$n = 5;
elseif ($num <= 100)
$n = 1;
else
throw new Exception('Incorrect value for number of required results');
$postData = array ('n' => $n, 'Gw' => $keywords);
$postData = http_build_query($postData);
$html = doPostRequest($this->url, $postData);
// This instruction is for testing only. I want to get results page here, but I get "sorry..." message.
echo $html;
}
}