Skip to content

Commit

Permalink
add ai_extract_rules
Browse files Browse the repository at this point in the history
  • Loading branch information
ziming committed Nov 19, 2024
1 parent 7bdeb21 commit e723174
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/LaravelScrapingBee.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Illuminate\Http\Client\Response;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Traits\Conditionable;
use JsonException;

final class LaravelScrapingBee
{
Expand Down Expand Up @@ -148,7 +149,7 @@ public function device(string $device): self
/**
* https://www.scrapingbee.com/documentation/#json_css
* https://www.scrapingbee.com/documentation/data-extraction/
* @throws \JsonException
* @throws JsonException
*/
public function extractDataFromCssRules(array $cssRules): self
{
Expand All @@ -174,6 +175,22 @@ public function aiQuery(string $query, ?string $selector = null): self
return $this;
}

/**
* https://www.scrapingbee.com/documentation/#ai_extract_rules
* https://www.scrapingbee.com/documentation/#ai_selector
* @throws JsonException
*/
public function aiExtractRules(array $rules, ?string $selector = null): self
{
$this->params['ai_extract_rules'] = json_encode($rules, JSON_THROW_ON_ERROR);

if ($selector !== null) {
$this->params['ai_selector'] = $selector;
}

return $this;
}

/**
* https://www.scrapingbee.com/documentation/#json_response
*/
Expand Down Expand Up @@ -267,6 +284,7 @@ public function disableJs(): self
/**
* https://www.scrapingbee.com/documentation/#javascript-execution
* https://www.scrapingbee.com/documentation/js-scenario/
* @throws JsonException
*/
public function jsScenario(array $instructions, bool $strict = true): self
{
Expand Down

0 comments on commit e723174

Please sign in to comment.