我试着通过来检查是否有酒店可用。我使用以下PHP代码:
<?php
//get date, in the future with $_POST
//get source
$source = file_get_contents('https://www.google.co.uk/hotelfinder/#search;l=london;d=2015-08-14;n=1;usd=1;h=17709217511794056234;si=;av=d');
//"Book a room" only shows when room(s) are available
if (strpos($source, "Book a room") !== false) {
echo "Room(s) available";
} else {
echo "Nothing available";
}
echo $source;
?> 当我在服务器上运行这段代码时,给出了以下错误消息:“尚未为您的浏览器进行优化。要获得最佳结果,请尝试Chrome、Firefox 3.5+、Internet 8+、Safari 4+”。所以谷歌发现我正在通过PHP访问页面..。有没有办法忽视或绕过这个“块”?
发布于 2015-08-14 16:11:00
您可以尝试发送带有标题的用户代理信息。
$options = array(
'http'=>array(
'method'=>"GET",
'header'=>"Accept-language: en\r\n" .
"Cookie: foo=bar\r\n" . // check function.stream-context-create on php.net
"User-Agent: Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B334b Safari/531.21.102011-10-16 20:23:10\r\n" // i.e. An iPad
)
);
$context = stream_context_create($options);
$file = file_get_contents($url, false, $context);https://stackoverflow.com/questions/32014160
复制相似问题