【问题标题】:503 Service Unavailable on Google Search503 服务在 Google 搜索上不可用
【发布时间】:2015-08-03 19:50:17
【问题描述】:

我正在使用 php 从谷歌搜索结果中提取数据。 这是我在 php 中的代码。

<?php
$url="https://www.google.co.in/search?      
q=allintext:Theatre%20Actors&sort=date&cr=countryIN&aqs=chrome..69i57.1033j0j7&sourceid=chrome&es_sm=93";
  $homepage = file_get_contents($url);
  $ans = htmlentities($homepage);
  $doc = new DOMDocument();
  @$doc->loadHTML($homepage);
  $tags = $doc->getElementsByTagName('h3');
  $finder = new DOMXPath($doc);
  $node = $finder->query("//h3[contains(@class, 'r')]");
  foreach ($node as $tag) {
   $temp = $tag->getElementsByTagName('a');               
   $string = "";
   foreach ($temp as $key) {
        $k=0;
        $data = $key->getAttribute('href');
        //echo $data;
        for($i=0;$i<strlen($data);$i++){
            if($data[$i]=="&") break;
            if($data[$i]=="="){
                $k=1; continue;
            }
            if($k==1){
                 $string.=$data[$i];   
            }
        }
   }
   $idx=  split(":", $string);
   if(strcmp($idx[0],"http")!=0 && strcmp($idx[0],'https')!=0)     continue; 
   $ans = '<a href='.$string.'>'.$string.'</a>';
   echo $ans;
   echo '<hr>';
  }
  ?>

运行此脚本后,我收到此错误: 警告:file_get_contents(https://www.google.co.in/search?q=allintext:Theatre%20Actors&sort=date&cr=countryIN&aqs=chrome..69i57.1033j0j7&sourceid=chrome&es_sm=93):打开流失败:HTTP 请求失败! HTTP/1.0 503 Service Unavailable in /opt/lampp/htdocs/search/script.php on line 4

请帮忙。 提前致谢。

【问题讨论】:

    标签: php


    【解决方案1】:

    也许 Google 会阻止您的请求: - 如果您过于频繁地运行脚本 - 谷歌本身不喜欢像'file_get_contents'这样的机器人

    另请参阅:HTTP request failed! HTTP/1.1 503 Service Temporarily Unavailable

    【讨论】:

    • 那么我应该怎么做才能获取数据呢?
    猜你喜欢
    • 1970-01-01
    • 2015-08-17
    • 1970-01-01
    • 2012-03-10
    • 2015-01-14
    • 2016-07-29
    • 2020-05-26
    • 2018-03-09
    • 2019-01-07
    相关资源
    最近更新 更多