Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/280.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 web爬虫中的HTTP 500错误_Php_Web Crawler - Fatal编程技术网

简单PHP web爬虫中的HTTP 500错误

简单PHP web爬虫中的HTTP 500错误,php,web-crawler,Php,Web Crawler,我正在尝试运行一个指向一个url的网络爬虫,它没有链接,代码看起来很好;但是,我得到了一个http 500错误 它对抓取的内容所做的只是回显它 知道为什么吗 <?php error_reporting( E_ERROR ); define( "CRAWL_LIMIT_PER_DOMAIN", 50 ); $domains = array(); $urls = array(); function crawl( $url ) { global $domains, $urls;

我正在尝试运行一个指向一个url的网络爬虫,它没有链接,代码看起来很好;但是,我得到了一个http 500错误

它对抓取的内容所做的只是回显它

知道为什么吗

<?php
error_reporting( E_ERROR );

define( "CRAWL_LIMIT_PER_DOMAIN", 50 );

$domains = array();

$urls = array();

function crawl( $url )
{
    global $domains, $urls;
    $parse = parse_url( $url );
    $domains[ $parse['host'] ]++;
    $urls[] = $url;

    $content = file_get_contents( $url );
    if ( $content === FALSE ){
        echo "Error: No content";
        return;
}

    $content = stristr( $content, "body" );
    preg_match_all( '/http:\/\/[^ "\']+/', $content, $matches );

    // do something with content.
    echo $content;

    foreach( $matches[0] as $crawled_url ) {
        $parse = parse_url( $crawled_url );
        if ( count( $domains[ $parse['host'] ] ) < CRAWL_LIMIT_PER_DOMAIN && !in_array( $crawled_url, $urls ) ) {
            sleep( 1 );
            crawl( $crawled_url );
        }
    }
}

crawl(http://the-irf.com/hello/hello6.html);
?>
替换:

crawl(http://the-irf.com/hello/hello6.html);
与:

URL是一个文本字符串,因此必须用引号括起来。


关于您在以下方面的问题:

返回从针的第一次出现开始到结束的所有haystack

因此,您的代码:

$content = stristr( $content, "body" );

将返回所有
$content
,从
body
的第一次出现开始,包括第一次出现的
body

您将从正在爬行的某个对象收到500?或者此代码正在您的服务器上生成一个500?如果是您的服务器,那么请检查服务器的错误日志-它将有关于500的更多详细信息。谢谢。这是因为文件内容需要URL在其周围加引号,对吗?
$content = stristr( $content, "body" );