2017-03-16 104 views
1

我試圖內Laravel 5.4使用cuab的PHPCrawl並通過作曲家採用這種封裝形式包括它: https://packagist.org/packages/mmerian/phpcrawl使用phpcrawl與Laravel 5.4

我試圖運行此示例代碼:

class MyCrawler extends PHPCrawler 
{ 
    function handleDocumentInfo($DocInfo) 
    { 
    if (PHP_SAPI == "cli"){ 
     $lb = "\n"; 
    } else { 
     $lb = "<br />"; 
    } 
    echo "Page requested: ".$DocInfo->url." (".$DocInfo->http_status_code.")".$lb; 
    echo "Referer-page: ".$DocInfo->referer_url.$lb; 

    if ($DocInfo->received == true) { 
     echo "Content received: ".$DocInfo->bytes_received." bytes".$lb; 
    } 
    else { 
     echo "Content not received".$lb; 
    } 

    echo $lb; 
    flush(); 
    } 
} 

$crawler = new MyCrawler(); 
$crawler->setURL("www.php.net"); 
$crawler->addContentTypeReceiveRule("#text/html#"); 
$crawler->addURLFilterRule("#\.(jpg|jpeg|gif|png)$# i"); 
$crawler->enableCookieHandling(true); 
$crawler->setTrafficLimit(1000 * 1024); 
$crawler->go(); 
$report = $crawler->getProcessReport(); 

if (PHP_SAPI == "cli") { 
    $lb = "\n"; 
} else { 
    $lb = "<br />"; 
} 

echo "Summary:".$lb; 
echo "Links followed: ".$report->links_followed.$lb; 
echo "Documents received: ".$report->files_received.$lb; 
echo "Bytes received: ".$report->bytes_received." bytes".$lb; 
echo "Process runtime: ".$report->process_runtime." sec".$lb; 

但它拋出多個錯誤是這樣的:

級 '應用程序\ HTTP \ \控制器PHPCrawler' 未找到

你會如何引用正確的命名空間,以便我可以在Laravel中使用該腳本?

+0

您可以手動添加文件,或者添加[class map](https://getcomposer.org/doc/04-schema.md#classmap)到您的composer.json文件 – Styphon

回答

2

您應該在composer.json文件中通過類映射添加文件。你可以看到的地圖類看起來像他們github page什麼,這在寫作的時候是這樣的一個例子:

"autoload": { 
    "classmap": [ 
     "libs/Utils/PHPCrawlerUtils.class.php", 
     "libs" 
    ] 
} 

你有vendor/mmerian/phpcrawl前綴的文件或任何的路徑是將libs文件夾。