Update MihaaruService.php
This commit is contained in:
		@@ -3,27 +3,30 @@
 | 
			
		||||
namespace App\Services;
 | 
			
		||||
 | 
			
		||||
use App\Services\Scrapers\MihaaruScraper;
 | 
			
		||||
use Illuminate\Support\Str;
 | 
			
		||||
 | 
			
		||||
class MihaaruService extends Client
 | 
			
		||||
{    
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * Scrap all the rss articles from mihaaru
 | 
			
		||||
     *
 | 
			
		||||
     * @return array
 | 
			
		||||
     */
 | 
			
		||||
    public function scrape() : array
 | 
			
		||||
    public function scrape(): array
 | 
			
		||||
    {
 | 
			
		||||
 | 
			
		||||
        $articles = $this->get("https://mihaaru.com/rss")["channel"]["item"];
 | 
			
		||||
        //Return only the rss that contains "news" keyboard in its url
 | 
			
		||||
        $articles = collect($this->get("https://mihaaru.com/rss")["channel"]["item"])
 | 
			
		||||
            ->filter(function ($item, $key) {
 | 
			
		||||
                return Str::of($item["link"])->contains(['news']);
 | 
			
		||||
            });
 | 
			
		||||
 | 
			
		||||
        $articlesitems = [];
 | 
			
		||||
        $scraper = new MihaaruScraper();
 | 
			
		||||
 | 
			
		||||
        //Looping through the articles and scraping and while scraping it creates a new instance of the scraper.
 | 
			
		||||
        foreach ($articles as $article) {
 | 
			
		||||
            $link = $article['link'];
 | 
			
		||||
            $date = $article['pubDate'];
 | 
			
		||||
            $guid = $article['guid'];
 | 
			
		||||
            $articlesitems[] = $scraper->extract($link, $date, $guid);
 | 
			
		||||
            $articlesitems[] = (new MihaaruScraper)->extract($link, $date, $guid);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return $articlesitems;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user