如何在JS上重定向时使用cURL获取目标URL?

时间:2016-10-09 19:24:37

标签: curl

如何在JS重定向后在cURL中获取目标URL页面?这段代码工作正确:

$url = 'http://google.com'; 
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
curl_setopt($ch, CURLOPT_TIMEOUT, 120);
$lastUrl = curl_exec($ch); 
$lastUrl = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
echo "Original: $url <br>Final: $lastUrl";
exit;

但如果使用此网址https://www.industrialsafety.com/search_results_a/256.html?Search=brady+76801最终网址相同,但应该是https://www.industrialsafety.com/Brady-76801-Brady-GlobalMark2-Color-Cut-p/cc-76801by.htm

1 个答案:

答案 0 :(得分:0)

三种选择:

  1. 查找PHP JS解释器扩展
  2. 将python与selenium一起使用
  3. 在PHP中编写链接转换例程以模拟下面的JS代码

    如果(pathname.match(&#39; /search_results_a/256.html')){
                    $(&#39;。内容&#39)。addClass(&#39; content_search&#39);                 $(&#39;&.content_search GT; DIV&#39;)addClass。(&#39; search_middle_content&#39);                 $(&#39;&.search_middle_content GT; DIV:当量(0)&#39)。addClass(&#39; search_left_bar&#39);                 $(&#39;#content_area&#39)。addClass(&#39; search_content&#39);                 $(&#39;&.search_content GT; DIV:当量(0)&#39)。addClass(&#39; main_search_content&#39);