Update MihaaruService.php
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
namespace App\Services;
|
namespace App\Services;
|
||||||
|
|
||||||
use App\Services\Scrapers\MihaaruScraper;
|
use App\Services\Scrapers\MihaaruScraper;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
class MihaaruService extends Client
|
class MihaaruService extends Client
|
||||||
{
|
{
|
||||||
@@ -11,19 +12,21 @@ class MihaaruService extends Client
|
|||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function scrape() : array
|
public function scrape(): array
|
||||||
{
|
{
|
||||||
|
//Return only the rss that contains "news" keyboard in its url
|
||||||
$articles = $this->get("https://mihaaru.com/rss")["channel"]["item"];
|
$articles = collect($this->get("https://mihaaru.com/rss")["channel"]["item"])
|
||||||
|
->filter(function ($item, $key) {
|
||||||
|
return Str::of($item["link"])->contains(['news']);
|
||||||
|
});
|
||||||
|
|
||||||
$articlesitems = [];
|
$articlesitems = [];
|
||||||
$scraper = new MihaaruScraper();
|
//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) {
|
||||||
$link = $article['link'];
|
$link = $article['link'];
|
||||||
$date = $article['pubDate'];
|
$date = $article['pubDate'];
|
||||||
$guid = $article['guid'];
|
$guid = $article['guid'];
|
||||||
$articlesitems[] = $scraper->extract($link, $date, $guid);
|
$articlesitems[] = (new MihaaruScraper)->extract($link, $date, $guid);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $articlesitems;
|
return $articlesitems;
|
||||||
|
|||||||
Reference in New Issue
Block a user