Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/265.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何将谷歌搜索结果从第1页刮到第2页_Php_Web Scraping_Scrape - Fatal编程技术网

Php 如何将谷歌搜索结果从第1页刮到第2页

Php 如何将谷歌搜索结果从第1页刮到第2页,php,web-scraping,scrape,Php,Web Scraping,Scrape,我想刮谷歌搜索结果到第2页,但我有我的网站空白页或超时结果的问题 for($j=0; $j<$acount; $j++){ sleep(60); for($sp = 0; $sp <= 10; $sp+=10){ $url = 'http://www.google.'.$lang.'/search?q='.$in.'&start='.$sp; if($sp == 10){

我想刮谷歌搜索结果到第2页,但我有我的网站空白页或超时结果的问题

for($j=0; $j<$acount; $j++){
sleep(60);
for($sp = 0; $sp <= 10; $sp+=10){
                        $url = 'http://www.google.'.$lang.'/search?q='.$in.'&start='.$sp;
                        if($sp == 10){
                            $datenbank = "proxy_work.php"; 
                            $datei = fopen($datenbank,"a+");
                            fwrite($datei, $data);  
                            fwrite ($datei,"\r\n");
                            fclose($datei);
                        } else {

                            $datenbank = "proxy_work.php"; 
                            $datei = fopen($datenbank,"w+");
                            fwrite($datei, $data);  
                            fwrite ($datei,"\r\n");
                            fclose($datei);
                        }
}
                        $html = file_get_html("proxy_work.php");
                        foreach($html->find('a') as $e){
                            //  $title = $h3->innertext;
                            $link  = $e->href;
                        if(in_array($endomain, $approveurl)){ 
                                }
                            // if it is not a direct link but url reference found inside it, then extract
                            if (!preg_match('/^https?/', $link) && preg_match('/q=(.+)&amp;sa=/U', $link, $matches) && preg_match('/^https?/', $matches[1])) {
                                $link = $matches[1];
                         } else if (!preg_match('/^https?/', $link)) { // skip if it is not a valid link
                                continue;
                            } 
                        }
用于($j=0;$jinnertext;
$link=$e->href;
if(在数组中($endomain,$approveurl)){
}
//如果它不是直接链接,而是在其中找到的url引用,则提取
如果(!preg_-match('/^https?/',$link)&&preg_-match('/q=(.+)&sa=/U',$link,$matches)&&preg_-match('/^https?/',$matches[1]){
$link=$matches[1];
}如果(!preg_match('/^https?/',$link)){//如果不是有效链接,则跳过
持续
} 
}

谷歌搜索结果页面(SERP)不象一个具有静态HTML的普通网站。谷歌将其数据保存在Web擦除中。将其数据视为<强>业务目录< /强>,见以下商业目录擦除的以下提示:

  • IP代理
  • 通过使用一些浏览器自动化工具(Selenium、iMacros等)模仿人类行为

  • 阅读更多信息。

    为什么要开始一个关于这个问题的新帖子?请继续关注这个话题:就像您关于这个问题的第一个问题一样……没有行代码,您尝试获取请求页面的结果,您只定义了URL。这回答了您的问题吗?它与本主题不同。本主题涉及最多刮取2页,但这s主题讨论仅抓取第2页。[link]CodyKL我通过将请求的页面保存在proxy_work.php文件名中来获得请求页面的结果