GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing roach-php.dev — Extensions — Roach PHP
Introduction
Advanced Usage ExtensionsExtend Roach by hooking into events which get fired during a run Extensions provide a way to extend Roach by hooking into the various events being fired throughout a run. Unlike downloader middleware, spider middleware, and item processors, Extensions don’t live inside a specific part of Roach’s lifecycle and as such can do things that regular middleware can’t. Writing ExtensionsAn extension is a class which implements We can see that all extensions are glorified event listeners. Every extension needs to provide a list of events it wants to listen on along with the event handler to be called when the event fires. Roach uses Symfony’s Defining Configuration OptionsCheck out the dedicated page about configuring middleware and extensions to learn how to define configuration options for our middleware. Built-in ExtensionsRoach ships with a few built-in extensions we can use in our spiders. LoggingThe built-in
By default, the extensions logs to To use this extension, add it to your spider’s This extension takes no configuration options. Collecting Run StatisticsThe After a run finishes, the extensions logs these statistics using its To use this extension, add it to your spider’s This extension takes no configuration options. EventsRoach fires various requests throughout a run which allow us to hook into various parts of a spider run’s lifecycle. Here’s a list of all events, when they get fired, and what their payload is.
|
| Property | Description |
|---|---|
run | The Run object containing the configuration of the run being started. |
RunFinishedFired after the last response was processed and no new requests were scheduled.
| Property | Description |
|---|---|
run | The Run object containing the configuration of the finished run. |
RequestSchedulingFired before a new request gets passed to the scheduler. Requests dropped at this point will not get scheduled and as such will not get passed through the downloader middleware.
| Property | Description |
|---|---|
request | The Request object about to be scheduled. |
RequestSendingFired right before a request gets sent. This event fires after the request was passed through the downloader middleware and wasn’t dropped. Requests dropped at this point will not get sent.
| Property | Description |
|---|---|
request | The Request object about to be sent. |
RequestDroppedFired whenever a request was dropped for any reason.
| Property | Description |
|---|---|
request | The dropped Request object. |
To get the drop reason, we can call the getDropReason method on the request object.
ResponseDroppedFired whenever a response was dropped by one of the spider middleware. Dropped responses will not get passed to the spider’s parse callback.
| Property | Description |
|---|---|
response | The dropped Response object. |
ItemScrapedFired when an item was passed through the item processing pipeline without being dropped.
| Property | Description |
|---|---|
item | The scraped ItemInterface. |
ItemDroppedFired whenever an item was dropped by one of the item processors.
| Property | Description |
|---|---|
item | The dropped ItemInterface. |
ResponseReceivingFired when the response of a request was received but before it is sent through the response middleware.
| Property | Description |
|---|---|
response | The Response object. |
ResponseReceivedFired after a response was sent through the response middleware without getting dropped.
| Property | Description |
|---|---|
response | The Response object. |