34 lines
		
	
	
		
			950 B
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			34 lines
		
	
	
		
			950 B
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?php
 | |
| 
 | |
| 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
 | |
|     {
 | |
|         //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 = [];
 | |
|         //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'];
 | |
|             $articlesitems[] = (new MihaaruScraper)->extract($link, $date);
 | |
|         }
 | |
| 
 | |
|         return $articlesitems;
 | |
|     }
 | |
| }
 |