Miadhu News Support
This commit is contained in:
44
app/Services/Feeds/MiadhuFeed.php
Normal file
44
app/Services/Feeds/MiadhuFeed.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Feeds;
|
||||
|
||||
use Goutte\Client;
|
||||
|
||||
class MiadhuFeed implements Feed
|
||||
{
|
||||
protected $client;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->client = new Client();
|
||||
}
|
||||
/**
|
||||
* Return the latest articles from avas
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get(): array
|
||||
{
|
||||
|
||||
$crawler = $this->client->request('GET', "https://miadhu.mv");
|
||||
|
||||
$feeds = [];
|
||||
$dates = [];
|
||||
|
||||
// scrape the dates for the articles
|
||||
$crawler->filter('.middle div[class*="col-md-3 col-6 news-block"] em')->each(function ($node) use (&$dates) {
|
||||
$dates[] = $node->text();
|
||||
});
|
||||
|
||||
$crawler->filter('.middle div[class*="col-md-3 col-6 news-block"] h2 a')->each(function ($node, $i) use (&$feeds, $dates) {
|
||||
$feeds[] = [
|
||||
"title" => $node->text(),
|
||||
"link" => $node->attr('href'),
|
||||
"date" => $dates[$i]
|
||||
];
|
||||
});
|
||||
|
||||
|
||||
return $feeds;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user