Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/231.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
简单HTML DOM PHP web爬虫程序不遵循初始爬网页面的链接_Php_Web Crawler_Simple Html Dom - Fatal编程技术网

简单HTML DOM PHP web爬虫程序不遵循初始爬网页面的链接

简单HTML DOM PHP web爬虫程序不遵循初始爬网页面的链接,php,web-crawler,simple-html-dom,Php,Web Crawler,Simple Html Dom,我正在使用一个PHP网络爬虫。这是我的密码: <?php include_once('simplehtmldom/simple_html_dom.php'); $seeds = [ 'http://www.google.com/?q=web+development#q=web+development', 'http://www.google.com/?q=art#q=art' ]; // Web crawl function crawl($seeds) {

我正在使用一个PHP网络爬虫。这是我的密码:

<?php

include_once('simplehtmldom/simple_html_dom.php');


$seeds = [
    'http://www.google.com/?q=web+development#q=web+development',
    'http://www.google.com/?q=art#q=art'
];

// Web crawl
function crawl($seeds) {
    foreach($seeds as $key) {
        $html = new simple_html_dom();
        $html->load_file($key);
        foreach ($html->find('a') as $link) {
            array_push($seeds, $link->href);
        }
    }
    $seeds = array_unique($seeds);
    print_r($seeds);
}

?>

字符串
simplehtmldom/simple\u html\u dom.php
是指向简单HTMLDOM的路径。问题是,它只对
$seeds
数组(“”,“)中的初始2个URL进行爬网。但是,我希望它能够抓取第二个
foreach
循环推送到数组的所有URL。我该如何解决这个问题


最后,处理不断增加的
$seeds
数组的最佳方法是什么?它将不停地不断爬行,所以我想跟踪所有的URL。我应该将它写入文件,还是在这么长时间后停止它是我最好的选择(最好的方法是什么?)?我需要能够在服务器上运行的另一个PHP文件中或从同一个PHP文件并行使用该数组。

我怀疑,如果您想对Google返回的任何内容进行爬网,您需要使函数递归(即,它使用新种子调用自身)。就更广泛的“如何”而言,有效管理所有种子链接可能是一项相当大的任务。从一开始可能更好吗?