Php 503服务在谷歌搜索上不可用

Php 503服务在谷歌搜索上不可用,php,Php,我使用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)

我使用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>';
  }
  ?>

也许谷歌会阻止你的请求:
-如果您的用户经常运行脚本
-谷歌本身不喜欢像“文件获取内容”这样的机器人


另请参见:

那么我应该如何获取数据?