在PHP中抓取链接不工作,但在浏览器中链接正常


Scraping a link in PHP not working, but link ok in browser

我正在尝试使用PHP抓取该页面的内容。

链接在浏览器中工作,但当使用curlget_file_contents时,booking.com网站报告该链接无效。我不确定这是否是防火墙问题与我的托管公司regg -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;

不是get_file_contents,而是file_get_contents:它只是完美地返回内容!我试过了。另外,我注意到在你的URL有一个不需要的空白,就在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;
?>