如何获取Curl的重定向URL

时间:2016-08-09 04:20:22

标签: php regex curl web-scraping preg-replace

我想使用curl废弃网页信息。这是我的脚本 -

$data[0] = "WP8558753";
$url = "http://www.searspartsdirect.com/part/search.html?q=".$data[0];
$ch = curl_init();  
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, true);  
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, "http://parts.sears.com/partsdirect/part-model/'".$data[0]."'?shdMod=".$data[0]); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
//curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

$output = curl_exec ($ch); 

echo curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);

curl_close ($ch); 

我想在变量中获取此网址http://www.searspartsdirect.com/part-number/WP8558753/0026/110.html?pathTaken=partSearch&q=WP8558753

我该怎么做..请提供一些指导。

1 个答案:

答案 0 :(得分:0)

您需要设置curl选项以遵循重定向

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);