From fb6daf45e39634550bc86aebe1fd6f1a6542504c Mon Sep 17 00:00:00 2001 From: Mohamed jinas Date: Thu, 10 Jun 2021 00:22:44 +0500 Subject: [PATCH] Fix thiladhun scraper --- app/Services/Scrapers/ThiladhunScraper.php | 3 ++- app/Services/ThiladhunService.php | 7 +++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/app/Services/Scrapers/ThiladhunScraper.php b/app/Services/Scrapers/ThiladhunScraper.php index 3d842e7..3ef4834 100644 --- a/app/Services/Scrapers/ThiladhunScraper.php +++ b/app/Services/Scrapers/ThiladhunScraper.php @@ -3,6 +3,7 @@ namespace App\Services\Scrapers; use Goutte\Client; +use Illuminate\Support\Carbon; class ThiladhunScraper { @@ -73,7 +74,7 @@ class ThiladhunScraper 'og_title' => str_replace(" | Thiladhun", "", $crawler->filter('title')->first()->text('content')), 'image' => $this->image, 'content' => $this->content, - 'date' => $date, + 'date' => Carbon::parse($date)->format("Y-m-d H:i:s"), 'url' => $url, 'author' => $this->author, 'guid' => basename($url), diff --git a/app/Services/ThiladhunService.php b/app/Services/ThiladhunService.php index b7f7b54..32f3d88 100644 --- a/app/Services/ThiladhunService.php +++ b/app/Services/ThiladhunService.php @@ -4,6 +4,7 @@ namespace App\Services; use App\Services\Feeds\ThiladhunFeed; use App\Services\Scrapers\ThiladhunScraper; +use Illuminate\Support\Facades\Http; class ThiladhunService extends Client { @@ -15,12 +16,14 @@ class ThiladhunService extends Client public function scrape(): array { //Return only the rss that contains "news" keyboard in its url - $articles = (new ThiladhunFeed)->get(); + $response = Http::get("https://thiladhun.com/feed")->body(); + $data = json_decode(json_encode(simplexml_load_string($response)), true); + $articles = $data["channel"]["item"]; $articlesitems = []; //Looping through the articles and scraping and while scraping it creates a new instance of the scraper. foreach ($articles as $article) { - $articlesitems[] = (new ThiladhunScraper)->extract($article["link"], $article["date"]); + $articlesitems[] = (new ThiladhunScraper)->extract($article["link"], $articles["pubDate"]); } return $articlesitems;