2013-05-30 64 views
-1

我試圖用PHP刮掉this頁面的內容。刮在PHP中的鏈接不工作,但在瀏覽器中鏈接正常

鏈接在瀏覽器中運行,但在使用curlget_file_contents時,booking.com網站會報告該鏈接無效。我不確定這是否是我的託管公司reg-123的防火牆問題?

任何人都可以幫忙嗎?使用

代碼如下:

$url='https://secure-admin.booking.com/booking.html?bn=600861417&hotel_id=279299&l ang=en&code=049ae718b3d22164934cf621bece92ad&message_num=1'; 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_HEADER, 1); 
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; MSIE 9.0; WIndows NT 9.0; en-US)'); 

$result = curl_exec($ch); 
echo $result; 
+4

你應該在booking.com問管理員,如果他們是與你沒關係刮他們的網站。也許他們故意阻止這樣的請求。 –

+0

你一定要將http://www.php.net/curl_getinfo添加到你的代碼中來查看請求和響應的詳細信息,以便能夠調試這個 –

回答

1

這不是get_file_contents,但file_get_contents: 它只是返回的內容完美!我嘗試過這個。此外,我注意到,在您的網址有一個多餘空白區域,剛過279299279299&l ang

<?php 
$contents = file_get_contents("https://secure-admin.booking.com/booking.html?bn=600861417&hotel_id=279299&lang=en&code=049ae718b3d22164934cf621bece92ad&message_num=1"); 

echo $contents; 
?> 
+0

啊 - 太簡單了!非常感謝你,這可能需要我花幾個小時才能找到。 – Paul

相關問題