Support for Avas mv
This commit is contained in:
71
app/Services/Scrapers/AvasScraper.php
Normal file
71
app/Services/Scrapers/AvasScraper.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
namespace App\Services\Scrapers;
|
||||
|
||||
use Goutte\Client;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
class AvasScraper
|
||||
{
|
||||
protected $client;
|
||||
|
||||
protected $content;
|
||||
protected $author;
|
||||
protected $topics = [];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->client = new Client;
|
||||
}
|
||||
|
||||
public function extract($url)
|
||||
{
|
||||
|
||||
$crawler = $this->client->request('GET', $url);
|
||||
|
||||
$title = $crawler->filter('h1')->first()->text();
|
||||
|
||||
|
||||
|
||||
$image = $crawler->filter('figure img')->first()->attr('src');
|
||||
|
||||
$crawler->filter('.post_content p')->each(function ($node) {
|
||||
$this->content[] = preg_replace("/[a-zA-Z]/","",$node->text());
|
||||
});
|
||||
|
||||
$crawler->filter('div[class*="border-t border-grey-light border-dotted mt-7 py-3"] a')->each(function ($node) {
|
||||
|
||||
//Removing the show more tags button
|
||||
if($node->text() == "+")
|
||||
{
|
||||
return;
|
||||
}
|
||||
$this->topics[] = [
|
||||
"name" => $node->text(),
|
||||
"slug" => str_replace("/", "", $node->attr('href'))
|
||||
];
|
||||
});
|
||||
|
||||
|
||||
|
||||
if($crawler->filter('div[class*="font-waheed text-grey ml-3 pl-3 text-lg border-l border-grey border-dotted"] a')->count() == 1)
|
||||
{
|
||||
$this->author = $crawler->filter('div[class*="font-waheed text-grey ml-3 pl-3 text-lg border-l border-grey border-dotted"] a')->first()->text();
|
||||
}
|
||||
|
||||
|
||||
//Remove all the alphabets from string
|
||||
//preg_replace("/[a-zA-Z]/", "",$string);
|
||||
return [
|
||||
'source' => 'Avas',
|
||||
'title' => $title,
|
||||
'og_title' => $crawler->filter('meta[property*="og:title"]')->first()->attr('content'),
|
||||
'image' => $image,
|
||||
'content' => $this->content,
|
||||
'url' => $url,
|
||||
'date' => Carbon::parse($crawler->filter('timeago')->first()->attr('datetime'))->format("Y-m-d H:i:s"),
|
||||
'guid' => str_replace("https://avas.mv/","",$url),
|
||||
'author' => $this->author,
|
||||
'topics' => $this->topics
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user