You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Im trying to get started with Roach and Laravel, but Im running into an issue when I add a custom Item Processor. I keep getting Illuminate\Container\EntryNotFoundException.
Here's what my code looks like:
// ParcelController.php
public function update(Request $request, string $id): RedirectResponse
{
Roach::startSpider(
LaravelDocsSpider::class,
new Overrides(
startUrls: ['https://roach-php.dev/docs/spiders']
)
);
}
// LaravelDocsSpider.php
<?php
namespace App\Spiders;
use App\Spiders\Processors\CustomProcessor;
use Generator;
use RoachPHP\Downloader\Middleware\RequestDeduplicationMiddleware;
use RoachPHP\Extensions\LoggerExtension;
use RoachPHP\Extensions\StatsCollectorExtension;
use RoachPHP\Http\Response;
use RoachPHP\Spider\BasicSpider;
use RoachPHP\Spider\ParseResult;
class LaravelDocsSpider extends BasicSpider
{
public array $startUrls = [
'https://roach-php.dev/docs/spiders'
];
public array $downloaderMiddleware = [
RequestDeduplicationMiddleware::class,
];
public array $spiderMiddleware = [
//
];
public array $itemProcessors = [
CustomProcessor::class,
];
public array $extensions = [
LoggerExtension::class,
StatsCollectorExtension::class,
];
public int $concurrency = 2;
public int $requestDelay = 1;
/**
* @return Generator<ParseResult>
*/
public function parse(Response $response): Generator
{
$title = $response->filter('h1')->text();
$subtitle = $response
->filter('main > div:nth-child(2) p:first-of-type')
->text();
// print_r([
// 'title' => $title,
// 'subtitle' => $subtitle
// ]);
yield $this->item([
'title' => $title,
'subtitle' => $subtitle,
]);
}
}
// CustomItemProcessor.php
<?php
namespace App\Spiders\Processors;
use RoachPHP\ItemPipeline\ItemInterface;
use RoachPHP\ItemPipeline\Processors\ItemProcessorInterface;
use RoachPHP\Support\Configurable;
class CustomProcessor implements ItemProcessorInterface
{
use Configurable;
public function processItem(ItemInterface $item): ItemInterface
{
print_r([
"title" => $item->title,
"subtitle" => $item->subtitle,
]);
return $item;
}
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Im trying to get started with Roach and Laravel, but Im running into an issue when I add a custom Item Processor. I keep getting
Illuminate\Container\EntryNotFoundException
.Here's what my code looks like:
Beta Was this translation helpful? Give feedback.
All reactions