Reference
Reference
Entry points
Scraper::run(...$params) |
Run it. Params go to handle(), positionally, by name, or as an assoc array. Returns a ScraperResponse. |
Scraper::with(...$props) |
Override properties (driver, tries, timeout, proxy, headers), returns a chainable wrapper. |
Scraper::make(...$deps) |
Build through the container without running. |
Scraper::withSession($session) |
Attach a shared cookie jar, statically. |
$scraper->useSession($session) |
Attach one to an instance, chainable. |
$scraper->handleToResponse([$params]) |
Drive a built instance directly. |
Crawler::run($input) |
Parse a document with no network. parse() is a legacy alias. |
Spider::run(...$params) |
Run a crawl. Returns whatever handle() returns. |
Scraper properties
| Default | ||
|---|---|---|
$driver |
'browser' |
'browser' or 'http'. |
$timeout |
20000 |
Milliseconds. |
$tries |
3 |
Attempts. |
$retryDelay |
15 |
Seconds between attempts. |
$headers |
[] |
Sent untouched, except User-Agent. |
$userAgent |
null |
null asks Chrome on the browser driver. |
$proxy, $proxyUser, $proxyPass |
null |
Wins over the config pool. |
$throttleKey |
null |
Falls back to the URL host. |
Inside handle(), $this->request is the RequestResponse of the last fetch: status, error, html, file, contentType, cookies.
The fetch chain
Configuration
->driver($name) |
'browser' or 'http'. |
->timeout($ms) |
|
->headers($array) |
|
->userAgent($string|null) |
|
->proxy($proxy, $user = null, $pass = null) |
First argument is string, not nullable. |
->retry($attempts, $seconds) |
|
->session($session) |
Request options, http driver only
->method($verb) |
|
->post($body = [], $format = 'form') |
|
->body($data) |
|
->asForm() / ->asJson() |
|
->cookies($pairs, $domain = null) |
Page actions, browser driver only
click · clickAndWait · type · select · setValue · check · uncheck · hover · press · waitForSelector · waitForNavigation · wait · scroll · scrollToBottom · submit · visit · gotoAttr · reload · solveCaptcha · capture · when · repeatUntil
See Page actions and Conditional flow.
Terminals
->run() |
ScraperResponse. |
->crawl($classOrSelector) |
Then ->run(), ->text() or ->texts(). |
->text() / ->texts() |
The first match, or all of them, as strings. |
->file() |
CapturedFile, or a no_file failure. |
->fetch() |
The RequestResponse itself. |
Crawler
$this->filter($css) |
Symfony DomCrawler node list over the HTML. |
$this->filter($css, 'xml') |
The same, filtering the input as XML. |
$this->raw() |
The untouched input. |
$this->html() |
The document as a string. |
Throw ScrapeException('code') to signal a content failure.
Responses
$result->data |
The parsed data, the raw return of handle(), or the HTML. |
$result->success |
Content-level success. |
$result->error |
A code such as 'captcha', never an HTTP status. |
Produced by returning a value, $this->ok($data), $this->fail('code'), or throwing ScrapeException.
Exceptions
RequestException |
The only one that reaches the caller. Carries ->response, so you can branch on ->status. |
ScrapeException |
Caught and folded into a failed ScraperResponse. |
ThrottledException |
The turn was further away than max_wait. |
LogicException |
Actions on http, or request options on browser. |
Conditions
Condition::selectorExists · selectorMissing · textContains · urlContains · captured
CapturedFile
->text($engine = 'gs') |
Text layer. Engines gs, poppler, smalot. '' when there is none. |
->vision($engine = 'ai') |
OCR of rasterized pages. Engines ai, tesseract. |
->bytes() / ->save($path) |
|
->contentType() / ->size() |
Spider
handle() |
Abstract. The whole orchestration. |
$concurrency |
Runs in flight per wave. 10. |
$delay |
Milliseconds between waves. 0. |
$this->session |
The shared jar. |
$this->pool($items, $scraper, $collect, $concurrency = null) |
$collect receives ($data, $item, $response). |
Session
->cookiesFor($host) |
|
->store($host, $pairs) |
Merge, last-wins. |
->all() |
Throttle
->lockedOut() |
Exits currently refused for this key. |
->available($label) |
|
->nextFreeIn($labels) |
Seconds until the first frees up. |
->forget() |
Wipe pacing and lockouts for this key. |
Config keys
proxies |
The pool. Strings or arrays, mixed. |
http_user_agent |
Default user agent for the http driver. |
throttle.{key} |
interval, lock_base, lock_max, max_wait. |
openai_key, vision_model, vision_lang, vision_dpi |
The ai vision engine. |
Retried statuses
408 · 429 · 500 · 502 · 503 · 504
Plus 403, but only while another exit is still free, and without the retry delay.
built and maintained by Edu Lazaro · MIT license