76 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			76 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?php
 | 
						|
 | 
						|
namespace App\Services\Scrapers;
 | 
						|
 | 
						|
use Goutte\Client;
 | 
						|
use Illuminate\Support\Carbon;
 | 
						|
 | 
						|
class FeshunScraper
 | 
						|
{
 | 
						|
    protected $client;
 | 
						|
 | 
						|
    protected $title;
 | 
						|
    protected $content;
 | 
						|
    protected $guid;
 | 
						|
    protected $author;
 | 
						|
 | 
						|
    /**
 | 
						|
     * __construct.
 | 
						|
     *
 | 
						|
     * @return void
 | 
						|
     */
 | 
						|
    public function __construct()
 | 
						|
    {
 | 
						|
        $this->client = new Client();
 | 
						|
    }
 | 
						|
 | 
						|
    /**
 | 
						|
     * extract.
 | 
						|
     *
 | 
						|
     * @param mixed $url
 | 
						|
     * @param mixed $date
 | 
						|
     * @param mixed $guid
 | 
						|
     *
 | 
						|
     * @return array
 | 
						|
     */
 | 
						|
    public function extract($url, $date)
 | 
						|
    {
 | 
						|
        $this->guid = str_replace('https://feshun.mv/', '', $url);
 | 
						|
 | 
						|
        $crawler = $this->client->request('GET', $url);
 | 
						|
 | 
						|
        $crawler->filter('h3')->each(function ($node) {
 | 
						|
            $this->title = $node->text();
 | 
						|
        });
 | 
						|
 | 
						|
 | 
						|
        $crawler->filter('.elementor-widget-container p')->each(function ($node) {
 | 
						|
            $this->content[] = preg_replace("/[a-zA-Z]/", "", $node->text());;
 | 
						|
        });
 | 
						|
 | 
						|
 | 
						|
        $crawler->filter('li[itemprop*="author"] span')->each(function ($node) {
 | 
						|
            $this->author = $node->text();
 | 
						|
        });
 | 
						|
 | 
						|
 | 
						|
        return [
 | 
						|
            'source'    => 'Feshun',
 | 
						|
            'title'      => $this->title,
 | 
						|
            'og_title'   => $crawler->filter('meta[property*="og:title"]')->first()->attr('content'),
 | 
						|
            'image'      => $crawler->filter('figure img')->first()->attr('src'),
 | 
						|
            'content'    => $this->content,
 | 
						|
            'date'       =>  Carbon::parse($date)->format("Y-m-d H:i:s"),
 | 
						|
            'url'        => $url,
 | 
						|
            'author'     => $this->author,
 | 
						|
            'guid'       => $this->guid,
 | 
						|
            'topics'       =>  [
 | 
						|
                [
 | 
						|
                    "name" => "ވަކި މަޢުލޫއެއް ނޭންގެ",
 | 
						|
                    "slug" => "no-specific-topic"
 | 
						|
                ]
 | 
						|
            ]
 | 
						|
        ];
 | 
						|
    }
 | 
						|
}
 |