Skip to content

Commit

Permalink
add new aiQuery method to LaravelScrapingBee class & remove timeout p…
Browse files Browse the repository at this point in the history
…arameter from LaravelScrapingBeeGoogleSearch class since no where in the code use it
  • Loading branch information
ziming committed Oct 6, 2024
1 parent 79f94d1 commit 7bdeb21
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
27 changes: 25 additions & 2 deletions src/LaravelScrapingBee.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,17 @@ private function request(string $method, string $url, array $data = [], string $
return $response;
}

/**
* @throws ConnectionException
*/
public function get(string $url): Response
{
return $this->request('GET', $url);
}

/**
* @throws ConnectionException
*/
public function post(string $url, array $data = [], string $postContentType = 'application/x-www-form-urlencoded; charset=utf-8'): Response
{
return $this->request('POST', $url, $data, $postContentType);
Expand Down Expand Up @@ -142,6 +148,7 @@ public function device(string $device): self
/**
* https://www.scrapingbee.com/documentation/#json_css
* https://www.scrapingbee.com/documentation/data-extraction/
* @throws \JsonException
*/
public function extractDataFromCssRules(array $cssRules): self
{
Expand All @@ -150,6 +157,23 @@ public function extractDataFromCssRules(array $cssRules): self
return $this;
}

/*
* https://www.scrapingbee.com/documentation/#ai_query
* https://www.scrapingbee.com/documentation/#ai_selector
*
* There is no aiSelector() method since it need to be used with aiQuery
*/
public function aiQuery(string $query, ?string $selector = null): self
{
$this->params['ai_query'] = $query;

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

return $this;
}

/**
* https://www.scrapingbee.com/documentation/#json_response
*/
Expand Down Expand Up @@ -387,8 +411,7 @@ public function output(string $output): self
/*
* This is for the situation if our API did not catch up and you want to add a new parameter
* that Scrapingbee supports
* like ->setParam('stealth_proxy', true) for example
* stealth proxy feature is in beta and hence I have not add a dedicated method to support it yet
* like ->setParam('new_beta_feature', true) for example
*/
public function setParam(string $key, mixed $value): self
{
Expand Down
2 changes: 1 addition & 1 deletion src/LaravelScrapingBeeGoogleSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static function make(#[\SensitiveParameter] ?string $apiKey = null): self
return new self($apiKey);
}

public function __construct(#[\SensitiveParameter] ?string $apiKey = null, ?int $timeout = null)
public function __construct(#[\SensitiveParameter] ?string $apiKey = null)
{
// If somebody pass '' into the constructor, we should use '' as the api key
// even if it doesn't make sense.
Expand Down

0 comments on commit 7bdeb21

Please sign in to comment.