Ciao a tutti.

stavo sviluppando un piccolo Crawler che estrae da una determinata pagina tutti gli URL presenti ...

A tale scopo ho trovato uno script già pronto e l'ho personalizzato in qualche punto ...

Ora dovrei creare un Array che contiene una BlackList con le Key da evitare. Quindi lo script prima di stampare l'URL dovrebbe controllare se all'interno della stringa che contiene l'URL è contenuta una Key bannata. In tal caso l'URL non andrebbe stampato ...

Qualche consiglio per fare ciò nel modo migliore???

Codice PHP:
ini_set('error_reporting'E_ALL);
ini_set("display_errors"1);

function 
crawl_page($url$depth 5)
{
    
    static 
$seen = array();
    if (isset(
$seen[$url]) || $depth === 0) {
        return;
    }
    
$seen[$url] = true;

    
$dom = new DOMDocument('1.0');
    @
$dom->loadHTMLFile($url);

    
$anchors $dom->getElementsByTagName('a');
    foreach (
$anchors as $element) {
        
$href $element->getAttribute('href');
        if (
!== strpos($href'http')) {
            
$path '/' ltrim($href'/');
            if (
extension_loaded('http')) {
                
$href http_build_url($url, array('path' => $path));
            } 
        }
        
        
            if(!
stristr($href"http")){
                
$dominio parse_url($urlPHP_URL_HOST);
                
$href "http://" $dominio "/" $href;
                echo 
$href "
"
;
            }
                if(
stristr($href$url)){
                
crawl_page($href$depth 1);
                
            }
            
        
        
//}
    
}
}
crawl_page("http://www.miosito.com"2);