Skip to content

Commit e723174

Browse files
committed
add ai_extract_rules
1 parent 7bdeb21 commit e723174

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/LaravelScrapingBee.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Illuminate\Http\Client\Response;
77
use Illuminate\Support\Facades\Http;
88
use Illuminate\Support\Traits\Conditionable;
9+
use JsonException;
910

1011
final class LaravelScrapingBee
1112
{
@@ -148,7 +149,7 @@ public function device(string $device): self
148149
/**
149150
* https://www.scrapingbee.com/documentation/#json_css
150151
* https://www.scrapingbee.com/documentation/data-extraction/
151-
* @throws \JsonException
152+
* @throws JsonException
152153
*/
153154
public function extractDataFromCssRules(array $cssRules): self
154155
{
@@ -174,6 +175,22 @@ public function aiQuery(string $query, ?string $selector = null): self
174175
return $this;
175176
}
176177

178+
/**
179+
* https://www.scrapingbee.com/documentation/#ai_extract_rules
180+
* https://www.scrapingbee.com/documentation/#ai_selector
181+
* @throws JsonException
182+
*/
183+
public function aiExtractRules(array $rules, ?string $selector = null): self
184+
{
185+
$this->params['ai_extract_rules'] = json_encode($rules, JSON_THROW_ON_ERROR);
186+
187+
if ($selector !== null) {
188+
$this->params['ai_selector'] = $selector;
189+
}
190+
191+
return $this;
192+
}
193+
177194
/**
178195
* https://www.scrapingbee.com/documentation/#json_response
179196
*/
@@ -267,6 +284,7 @@ public function disableJs(): self
267284
/**
268285
* https://www.scrapingbee.com/documentation/#javascript-execution
269286
* https://www.scrapingbee.com/documentation/js-scenario/
287+
* @throws JsonException
270288
*/
271289
public function jsScenario(array $instructions, bool $strict = true): self
272290
{

0 commit comments

Comments
 (0)