2017-01-10 101 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