Fix mihaaru scraper

This commit is contained in:
Mohamed jinas
2024-01-13 04:53:31 +05:00
parent 252d750d7d
commit 736181d461
5 changed files with 96 additions and 24 deletions
+3 -8
View File
@@ -2,6 +2,7 @@
namespace App\Services;
use App\Services\Feeds\MihaaruFeed;
use App\Services\Scrapers\MihaaruScraper;
use Illuminate\Support\Str;
@@ -15,17 +16,11 @@ class MihaaruService extends Client
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']);
});
$articles = (new MihaaruFeed)->get();
$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);
$articlesitems[] = (new MihaaruScraper)->extract($article['link'], $article['date']);
}
return $articlesitems;