siteorigin/laravel-kernel-crawler

使用内部Kernel爬取Laravel站点

0.1.0 2021-03-05 09:43 UTC

This package is auto-updated.

Last update: 2024-09-05 17:16:55 UTC


README

此包提供基于Laravel LazyCollection的本地站点爬虫。每个请求都直接通过本地HTTPKernel,因此不会生成Web服务器请求。

你可能需要此包的两个例子是预热站点缓存和生成站点地图。此包提供这两个操作的命令。

目前与Laravel 8.0+兼容

安装

安装说明将在包上传到Packagist后提供。

要发布配置文件,请使用

php artisan vendor:publish --provider="SiteOrigin\KernelCrawler\CrawlerServiceProvider" --tag="config"

用法

以下是一个非常基础的用法示例

use SiteOrigin\KernelCrawler\Crawler;
use SiteOrigin\KernelCrawler\Exchange;


$crawler = new Crawler();
$crawler->each(function(Exchange $ex){
	// $ex->request is an Illuminate\Http\Request object
	$ex->request->url();
	// $ex->response is an Illuminate\Http\Response object
	$ex->response->getContent()
});

创建爬虫后,你可以使用所有的Laravel LazyCollection 函数。这提供了一组 Exchange 对象。

预热缓存

如果你只需要为你的站点上的每个公开URL生成模拟请求,那么你可以使用 php arisan crawler:start。如果你想要预热网站上所有公开URL的缓存,这将非常有用。

生成站点地图

此包提供 php artisan crawler:sitemap 命令来生成站点地图。你可以使用 crawler.php 配置文件配置你的站点地图。有关发布此配置文件的说明,请参阅安装部分。