Fix thiladhun scraper
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
namespace App\Services\Scrapers;
|
namespace App\Services\Scrapers;
|
||||||
|
|
||||||
use Goutte\Client;
|
use Goutte\Client;
|
||||||
|
use Illuminate\Support\Carbon;
|
||||||
|
|
||||||
class ThiladhunScraper
|
class ThiladhunScraper
|
||||||
{
|
{
|
||||||
@@ -73,7 +74,7 @@ class ThiladhunScraper
|
|||||||
'og_title' => str_replace(" | Thiladhun", "", $crawler->filter('title')->first()->text('content')),
|
'og_title' => str_replace(" | Thiladhun", "", $crawler->filter('title')->first()->text('content')),
|
||||||
'image' => $this->image,
|
'image' => $this->image,
|
||||||
'content' => $this->content,
|
'content' => $this->content,
|
||||||
'date' => $date,
|
'date' => Carbon::parse($date)->format("Y-m-d H:i:s"),
|
||||||
'url' => $url,
|
'url' => $url,
|
||||||
'author' => $this->author,
|
'author' => $this->author,
|
||||||
'guid' => basename($url),
|
'guid' => basename($url),
|
||||||
|
@@ -4,6 +4,7 @@ namespace App\Services;
|
|||||||
|
|
||||||
use App\Services\Feeds\ThiladhunFeed;
|
use App\Services\Feeds\ThiladhunFeed;
|
||||||
use App\Services\Scrapers\ThiladhunScraper;
|
use App\Services\Scrapers\ThiladhunScraper;
|
||||||
|
use Illuminate\Support\Facades\Http;
|
||||||
|
|
||||||
class ThiladhunService extends Client
|
class ThiladhunService extends Client
|
||||||
{
|
{
|
||||||
@@ -15,12 +16,14 @@ class ThiladhunService extends Client
|
|||||||
public function scrape(): array
|
public function scrape(): array
|
||||||
{
|
{
|
||||||
//Return only the rss that contains "news" keyboard in its url
|
//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 = [];
|
$articlesitems = [];
|
||||||
//Looping through the articles and scraping and while scraping it creates a new instance of the scraper.
|
//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) {
|
||||||
$articlesitems[] = (new ThiladhunScraper)->extract($article["link"], $article["date"]);
|
$articlesitems[] = (new ThiladhunScraper)->extract($article["link"], $articles["pubDate"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $articlesitems;
|
return $articlesitems;
|
||||||
|
Reference in New Issue
Block a user