繁体   English   中英

如何获取Curl的重定向URL

[英]How to get Redirect URL of Curl

我想使用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

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

您需要设置curl选项以跟随重定向

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM