我正在尝试使用PHP抓取this页面的内容。
链接可在浏览器中使用,但在使用curl
或get_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;
答案 0 :(得分: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;
?>