add method to setCrawlProfile, add type hinting
This commit is contained in:
parent
35aeeeca72
commit
bea673807c
@ -10,13 +10,14 @@ use Psr\Http\Message\UriInterface;
|
||||
use Spatie\Crawler\Crawler as SpatieCrawler;
|
||||
use Spatie\Crawler\CrawlUrl;
|
||||
use Spatie\Crawler\CrawlAllUrls;
|
||||
use Spatie\Crawler\CrawlProfile;
|
||||
|
||||
class Crawler{
|
||||
|
||||
private $observer;
|
||||
private $crawler;
|
||||
|
||||
public function __construct($reqOps=[]){
|
||||
public function __construct(array $reqOps=[]){
|
||||
$this->crawler = SpatieCrawler::create(array_merge($reqOps, [
|
||||
RequestOptions::ALLOW_REDIRECTS => [
|
||||
'track_redirects' => true,
|
||||
@ -28,15 +29,21 @@ class Crawler{
|
||||
$this->crawler->setCrawlProfile(new CrawlAllUrls());
|
||||
}
|
||||
|
||||
public function setUserAgent($agent){
|
||||
public function setUserAgent(String $agent) : self{
|
||||
$this->crawler->setUserAgent($agent);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function crawl($url){
|
||||
public function setCrawlProfile(CrawlProfile $p) : self{
|
||||
$this->crawler->setCrawlProfile($p);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function crawl(String $url) : void{
|
||||
$this->crawler->startCrawling($url);
|
||||
}
|
||||
|
||||
public function getResults(){
|
||||
public function getResults() : array{
|
||||
return $this->observer->results;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user