Fix thiladhun scraper

This commit is contained in:
2021-06-10 00:22:44 +05:00
parent 4629067572
commit fb6daf45e3
2 changed files with 7 additions and 3 deletions

View File

@@ -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),

View File

@@ -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;