Spatie\Crawler\CrawlQueue::getPendingUrlAtIndex PHP Method

getPendingUrlAtIndex() public method

public getPendingUrlAtIndex ( integer $index ) : CrawlUrl | null
$index integer
return CrawlUrl | null
    public function getPendingUrlAtIndex(int $index)
    {
        if (!isset($this->getPendingUrls()[$index])) {
            return;
        }
        return $this->getPendingUrls()[$index];
    }

Usage Example

Example #1
0
 protected function getCrawlRequests() : Generator
 {
     $i = 0;
     while ($crawlUrl = $this->crawlQueue->getPendingUrlAtIndex($i)) {
         if (!$this->crawlProfile->shouldCrawl($crawlUrl->url)) {
             $i++;
             continue;
         }
         if ($this->crawlQueue->hasAlreadyBeenProcessed($crawlUrl)) {
             $i++;
             continue;
         }
         $this->crawlObserver->willCrawl($crawlUrl->url);
         $this->crawlQueue->markAsProcessed($crawlUrl);
         (yield new Request('GET', (string) $crawlUrl->url));
         $i++;
     }
 }