Hama news intergration
This commit is contained in:
39
app/Services/Feeds/HamaFeed.php
Normal file
39
app/Services/Feeds/HamaFeed.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
namespace App\Services\Feeds;
|
||||
|
||||
use Goutte\Client;
|
||||
|
||||
class HamaFeed implements Feed
|
||||
{
|
||||
protected $client;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->client = new Client();
|
||||
}
|
||||
/**
|
||||
* Get all the latest news
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get() : array
|
||||
{
|
||||
|
||||
$crawler = $this->client->request('GET', "https://hama.mv/");
|
||||
|
||||
$feeds = [];
|
||||
$crawler->filter('div[id*="latest"] div[class*="col-md-3 col-6"] a')->each(function ($node) use (&$feeds) {
|
||||
|
||||
|
||||
$feeds[] = [
|
||||
"title" => $node->filter('h5')->first()->text(),
|
||||
"link" => $node->attr('href'),
|
||||
"date" => $node->filter('.datetime')->first()->text()
|
||||
];
|
||||
|
||||
});
|
||||
|
||||
return $feeds;
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user