2017-01-10 98 views
0

在这个脚本中,curl工作正常。 $ output有页面,但是当我尝试回显它的源代码时,它什么都不显示。我认为它与页面标题有关。任何帮助!卷曲,没有获取页面源代码

header('content-type:text/plain'); 
$ch = curl_init(); 
$url = "https://www.amazon.com/gp/css/shiptrack/view.html/ref=TE_SIMP_typ?ie=UTF8&addressID=olqnkqjstjp&latestArrivalDate=1483848000&orderID=103-0753412-5410653&shipmentDate=1483706902&orderingShipmentId=4160817392100&packageId=1"; 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_HEADER, false); 

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($curl, CURLOPT_BINARYTRANSFER, true); 
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); 

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); 
curl_setopt($ch, CURLOPT_MAXREDIRS, 1); 
$output = curl_exec($ch); 
curl_close($ch); 
echo $output; 
+0

为什么downvote。什么不清楚。调试时使用 –

+0

,使用var_dump,而不是echo。 var_dump保证给出一些输出,var_dump说什么? (最有可能的是,它说bool(false),这意味着curl有错误,在这种情况下,使用curl_error($ ch)获取更多信息) – hanshenrik

+0

似乎你运行时没有错误报告,并且引用一个未定义的变量$ curl(因为你想要的变量叫做$ ch,$ curl是未定义的),脚本崩溃了,但是在php.ini中没有error_reporting,你只是得到一个空白页并且没有错误日志 - 确保php.ini包含'error_reporting = E_ALL',并再次运行代码,错误应该从错误日志中显而易见 – hanshenrik

回答

0

我已修改您的代码.. 试试这个。

删除
报头( '内容类型:文本/无格式');

并用我的代码替换你的代码。

$ch = curl_init(); 
$url = "https://www.amazon.com/gp/css/shiptrack/view.html/ref=TE_SIMP_typ?ie=UTF8&addressID=olqnkqjstjp&latestArrivalDate=1483848000&orderID=103-0753412-5410653&shipmentDate=1483706902&orderingShipmentId=4160817392100&packageId=1"; 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_HEADER, false); 

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); 
curl_setopt($ch, CURLOPT_MAXREDIRS, 1); 
$output = curl_exec($ch); 
curl_close($ch); 
echo $output; 

编辑

既然你想ctrl+u

这里是PHP代码获取指定的任何网站的HTML源代码。 fopen功能用于打开网站的URL。 stream_get_contents用于读取打开的URL。获取的代码显示在textarea中。

$domain = 'https://www.amazon.com/gp/css/shiptrack/view.html/ref=TE_SIMP_typ?ie=UTF8&addressID=olqnkqjstjp&latestArrivalDate=1483848000&orderID=103-0753412-5410653&shipmentDate=1483706902&orderingShipmentId=4160817392100&packageId=1'; 
$handle = fopen($domain, 'r'); 
$content = stream_get_contents($handle); 
/** 
// alternative to stream_get_contents 
$contents = ''; 
while (!feof($handle)) { 
    $content .= fread($handle, 8192); 
} 
**/ 
fclose($handle); 
/** 
* print html content on textarea 
*/ 
echo "<textarea rows='20' cols='80'>$content</textarea>"; 

输出将是这样的: enter image description here

OR

另外如果你想以某种方式操纵检索到的页面,你可能 想尝试一些PHP DOM解析器。我发现PHP Simple HTML DOM Parser非常容易使用。

+0

$ output有页面,但我想要得到它的html,那就是我正面临问题的地方。 –

+0

你是什么意思@RajeevSingh由html ????你想在浏览器上显示它? –

+0

拉杰夫辛格我没有得到你..你能详细说明吗?我以为你有问题与你的卷曲 – NID