如何获取页面内容后重定向通过PHP在PHP [英] How to get page contents after redirect by javascript in php
问题描述
如何通过javascript在网页重定向后获取整个网页内容?
在 executewebpage.php 中:
<?php
$ ch = curl_init();
curl_setopt($ ch,CURLOPT_HEADER,TRUE);
curl_setopt($ ch,CURLOPT_RETURNTRANSFER,TRUE);
curl_setopt($ ch,CURLOPT_FOLLOWLOCATION,TRUE);
curl_setopt($ ch,CURLOPT_SSL_VERIFYPEER,FALSE);
curl_setOpt($ ch,CURLOPT_POST,TRUE);
$ url ='http://www.doredirect.com';
$ postfields = array('doredirect'=>'true','trigger'=>'1');
curl_setopt($ ch,CURLOPT_POSTFIELDS,$ postfields);
curl_setopt($ ch,CURLOPT_URL,$ url);
$ data = curl_exec($ ch);
echo($ data); //在这一步,它重定向到页面:http://www.finalpage.com
curl_close($ ch);
如何获取 http://www.finalpage.com ?
注意:如果我不回音,则不返回任何内容,不重定向到任何网页 >
非常感谢!
尝试使用此方法查看HTML卷曲回应:
echo htmlspecialchars($ data);
很可能在某处存在javascript或元重定向。寻找这个:
window.location ...
或
document.location ...
或
meta http-equiv =refreshcontent =0; url = http://finalpage.com/>
从这里,你可以建立一个正则表达式fetch它的内容。
How can I get whole page contents after that page redirect by javascript?
In executewebpage.php:
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setOpt($ch, CURLOPT_POST, TRUE);
$url = 'http://www.doredirect.com';
$postfields = array('doredirect'=>'true','trigger'=>'1');
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
curl_setopt($ch, CURLOPT_URL, $url);
$data = curl_exec($ch);
echo($data); //In this step, it redirect to page: http://www.finalpage.com
curl_close($ch);
How can I get contents of http://www.finalpage.com?
Note:If I don't echo, it don't return anything and don't redirect to any page
Thank you so much!
Try using this to view the HTML of the curl response:
echo htmlspecialchars($data);
It's likely that there is a javascript or meta redirect in there somewhere. Look for this:
window.location...
or
document.location...
or
<meta http-equiv="refresh" content="0;url=http://finalpage.com" />
From there, you can build a regular expression (as others have suggested) to find the URL and then fetch it's contents.
这篇关于如何获取页面内容后重定向通过PHP在PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!