我要抓http://www.car4you.at/Haendlersuche 它显示20个结果第一次和分页。我成功地抓取了20个链接,但由于分页中没有链接,因此无法链接到下一页。它包含一个javascript函数。用curl打开网址,点击ajax按钮,等待并得到回复html
href="javascript:AjaxCallback_ResList('ResultList', 'Pager', '1_1874')"
我的问题是如何加载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;
}
的
功能,并试图代码是分页
$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']);
}
刮第二个方法是选择列表,显示像 10个结果如果我的脚本成功选择50那么它也就会b Ë快乐工作 并试图代码是选择列表
$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']);
}
我现在正面临同样的问题! – sunny
嗯如果你得到解决方案,请在这里提供 –
m对不起!我真的没有一个!我转向了一个没有分页的页面! – sunny