php curl - 与浏览器不同的结果

时间:2016-07-03 02:05:46

标签: php curl

我试图从此网址获取数据:http://www.fler.cz/shop/dara-bags?f14=2&onpage=72

当我在浏览器中打开它时,页面上有72个项目,但是当我通过curl尝试它时只有18个。所以似乎“onpage =”参数可以正常工作。但是设置显示页数的参数“f14 =”正在工作。为什么第二个参数不起作用?谢谢。

以下是代码:

$source = "http://www.fler.cz/shop/dara-bags?f14=2&onpage=72";

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $source);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

$data = curl_exec ($ch);
curl_close ($ch);
echo $data;

1 个答案:

答案 0 :(得分:0)

将其作为数组传递

$ch = curl_init(); 
$source = "http://www.fler.cz/shop/dara-bags"
$data = array('f14' => '2', 'onpage' => '72');
$handle = curl_init($source);
curl_setopt($handle, CURLOPT_POST, true);
curl_setopt($handle, CURLOPT_POSTFIELDS, $data);
curl_exec($ch);

或者您可以使用以下代码发送GET请求

$ch = curl_init(); 
$source = "http://www.fler.cz/shop/dara-bags?f14=2&onpage=72";  
curl_setopt($ch,CURLOPT_URL,$source);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);

$output=curl_exec($ch);
curl_close($ch);
return $output;
相关问题