【问题标题】:PHP server hitting https://www.google.com/movies gets no resultsPHP 服务器点击 https://www.google.com/movies 没有结果
【发布时间】:2024-01-21 10:14:01
【问题描述】:

如果您转到https://www.google.com/movies?near=02215&q=revenant,您将清楚地得到可以解析的结果返回给您。但是,当我将一个小脚本上传到我的服务器时,例如:

<?php 

$string = file_get_contents("https://www.google.com/movies?near=02215&q=revenant");

echo $string;

?>

结果的输出类似于“未找到结果”

有什么想法吗?

【问题讨论】:

  • 当我在 Chrome 中测试该 URL 时,我得到“No hits”。
  • Your query - revenant - did not match any movie reviews, showtimes or theaters. - 看起来是您访问的网址
  • 问题仍然存在,无论查询什么,从服务器完成后它永远不会返回结果
  • @jlane09 看来你不是第一个*.com/questions/9379555/…

标签: php search search-engine file-get-contents movies


【解决方案1】:

Google 对他们向谁发送 HTTP 响应很挑剔,告诉他们你是浏览器,看看这是否有效:

$context = stream_context_create(array(
    'http' => array(
        'method' => "GET",
        'header' => "" .
            "Accept: text/html" . "\r\n" .
            "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:43.0) Gecko/20100101 Firefox/43.0" . "\r\n"
    )
));

$string = file_get_contents( "https://www.google.com/movies?near=02215&q=revenant", false, $context );

【讨论】:

  • @jlane09 该死的,我一开始得到的结果是空白的,但在我添加标题后对我有用。尝试使用 CURL。
  • 也许我的服务器已经被列入了一些列表,但我也会尝试使用 curl