switched the press to a virtual feed
This commit is contained in:
37
app/Services/Feeds/ThePressFeed.php
Normal file
37
app/Services/Feeds/ThePressFeed.php
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
namespace App\Services\Feeds;
|
||||||
|
|
||||||
|
use Goutte\Client;
|
||||||
|
|
||||||
|
class ThePressFeed
|
||||||
|
{
|
||||||
|
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://thepress.mv/");
|
||||||
|
|
||||||
|
$feeds = [];
|
||||||
|
|
||||||
|
$crawler->filter('div[class*="col-lg-3 col-lg-cm-5 col-md-6 col-6"] a')->each(function($node) use (&$feeds){
|
||||||
|
$feeds[] = [
|
||||||
|
"title" => $node->text(),
|
||||||
|
"link" => $node->attr('href')
|
||||||
|
];
|
||||||
|
});
|
||||||
|
|
||||||
|
return $feeds;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@
|
|||||||
namespace App\Services;
|
namespace App\Services;
|
||||||
|
|
||||||
use App\Services\Scrapers\ThePressScraper;
|
use App\Services\Scrapers\ThePressScraper;
|
||||||
|
use App\Services\Feeds\ThePressFeed;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
class ThePressService extends Client
|
class ThePressService extends Client
|
||||||
@@ -15,7 +16,7 @@ class ThePressService 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 = $this->get("https://thepress.mv/rss")["channel"]["item"];
|
$articles = (new ThePressFeed)->get();
|
||||||
|
|
||||||
|
|
||||||
$articlesitems = [];
|
$articlesitems = [];
|
||||||
|
|||||||
Reference in New Issue
Block a user