我正在尝试在 Laravel 5.4 中使用 cuab 的 PHPCrawl,并使用此包通过作曲家将其包含在内: https ://packagist.org/packages/mmerian/phpcrawl
我试过运行这个示例代码:
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;
但它会引发多个这样的错误:
找不到类“App\Http\Controllers\PHPCrawler”
您将如何引用正确的命名空间以便我可以在 Laravel 中使用该脚本?