Skip to content

Commit

Permalink
Add jsScenario(array $instructions) method
Browse files Browse the repository at this point in the history
  • Loading branch information
ziming committed Dec 27, 2021
1 parent d2714dd commit f7da061
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ $response = $scrapingBeeClient->blockAds()
->get('https://www.scrapingbee.com')
```

Look at the source code of `src/LaravelScrapingBee.php` for the other methods (link below). More proper documentation will be added later. Methods that return `$this` are chainable. An example is the `blockAds()` method you saw above.
Look at the source code of `src/LaravelScrapingBee.php` for the other methods (link below). More proper documentation will be added later. Methods that return `$this` are chainable. An example is the `blockAds()` method you saw above. Meanwhile methods such as `get()`, `post()`, `usageStatistics()` returns you an `Illuminate\Http\Client\Response` object if no exceptions are thrown.

[LaravelScrapingBee.php](https://github.com/ziming/laravel-scrapingbee/blob/main/src/LaravelScrapingBee.php)

Expand Down
13 changes: 12 additions & 1 deletion src/LaravelScrapingBee.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ public function post(string $url, array $data = [], string $postContentType = 'a
*/
private function setUrl(string $url): self
{
// urlencode make things fail somehow. Maybe urlencode is run at the Http::get() / Http::post() level
// urlencode($url) make things fail somehow.
// My guess is urlencode is run at the Http::get() / Http::post() level already
$this->params['url'] = $url;

return $this;
Expand Down Expand Up @@ -231,6 +232,16 @@ public function disableJs(): self
return $this;
}

/**
* https://www.scrapingbee.com/documentation/#javascript-execution
*/
public function jsScenario(array $instructions): self
{
$this->params['js_scenario'] = json_encode($instructions);

return $this;
}

/**
* https://www.scrapingbee.com/documentation/#page-source
*/
Expand Down

0 comments on commit f7da061

Please sign in to comment.