Update MihaaruService.php

This commit is contained in:
2020-08-10 06:17:41 +05:00
parent f993ae47e3
commit cbe2c59898

View File

@@ -3,27 +3,30 @@
namespace App\Services; namespace App\Services;
use App\Services\Scrapers\MihaaruScraper; use App\Services\Scrapers\MihaaruScraper;
use Illuminate\Support\Str;
class MihaaruService extends Client class MihaaruService extends Client
{ {
/** /**
* Scrap all the rss articles from mihaaru * Scrap all the rss articles from mihaaru
* *
* @return array * @return array
*/ */
public function scrape() : array public function scrape(): array
{ {
//Return only the rss that contains "news" keyboard in its url
$articles = $this->get("https://mihaaru.com/rss")["channel"]["item"]; $articles = collect($this->get("https://mihaaru.com/rss")["channel"]["item"])
->filter(function ($item, $key) {
return Str::of($item["link"])->contains(['news']);
});
$articlesitems = []; $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) { foreach ($articles as $article) {
$link = $article['link']; $link = $article['link'];
$date = $article['pubDate']; $date = $article['pubDate'];
$guid = $article['guid']; $guid = $article['guid'];
$articlesitems[] = $scraper->extract($link, $date, $guid); $articlesitems[] = (new MihaaruScraper)->extract($link, $date, $guid);
} }
return $articlesitems; return $articlesitems;