I am going to scrape http://www.car4you.at/Haendlersuche it shows 20 results first time and pagination. I scrape 20 links successfully but facing problem to get link to next page because there is no link in href of pagination. It contains a javascript function.
href="javascript:AjaxCallback_ResList('ResultList', 'Pager', '1_1874')"
My question is how can I load page with curl then click on next page button, wait for response then parse it.
Here is what I am trying
function of curl
function postCurlReq($loginActionUrl,$parameters,$referer)
{
curl_setopt ($this->curl, CURLOPT_URL,$loginActionUrl);
curl_setopt ($this->curl, CURLOPT_POST, 1);
curl_setopt ($this->curl, CURLOPT_POSTFIELDS, $parameters);
curl_setopt ($this->curl, CURLOPT_COOKIEJAR, realpath('cookie.txt')); // cookie.txt should be in same directoy, where calling script is
curl_setopt ($this->curl, CURLOPT_COOKIEFILE, realpath('cookie.txt'));
curl_setopt ($this->curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($this->curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($this->curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; U; Linux i586; de; rv:5.0) Gecko/20100101 Firefox/5.0');
curl_setopt ($this->curl, CURLOPT_REFERER, $referer); // set referer
curl_setopt ($this->curl, CURLOPT_SSL_VERIFYPEER, FALSE);// ssl certificate
curl_setopt ($this->curl, CURLOPT_SSL_VERIFYHOST, 2);
$result['EXE'] = curl_exec($this->curl);
$result['INF'] = curl_getinfo($this->curl);
$result['ERR'] = curl_error($this->curl);
return $result;
}
and tried code is for pagination
$loginUrl = "http://www.car4you.at/Haendlersuche";
$parameters = array("href" => "javascript:AjaxCallback_ResList('ResultList', 'Pager', '1_1874')");
$referer = "http://www.car4you.at/Haendlersuche";
$loginHTML = $crawler->postCurlReq($loginUrl,$parameters,$referer);
if ( empty($loginHTML['ERR']) ) { // if no error occure in opening url
print_r($loginHTML['EXE']);
}
second method to scrape is select list that show results like 10 20 50 if my script succeed to select 50 then it ll also be happy work and tried code is for select list
$loginUrl = "http://www.car4you.at/Haendlersuche";
$parameters = array("value" => "50");
$referer = "http://www.car4you.at/Haendlersuche";
$loginHTML = $crawler->postCurlReq($loginUrl,$parameters,$referer);
if ( empty($loginHTML['ERR']) ) { // if no error occure in opening url
print_r($loginHTML['EXE']);
}