Addulive intergration
This commit is contained in:
62
app/Services/Scrapers/AdduLiveScraper.php
Normal file
62
app/Services/Scrapers/AdduLiveScraper.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
namespace App\Services\Scrapers;
|
||||
|
||||
use Goutte\Client;
|
||||
|
||||
class AdduLiveScraper
|
||||
{
|
||||
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('article .entry-featured-image img')->first()->attr('src');
|
||||
|
||||
$crawler->filter('article p')->each(function ($node) {
|
||||
$this->content[] = preg_replace("/[a-zA-Z]/","",$node->text());
|
||||
});
|
||||
|
||||
$crawler->filter('.entry-categories a')->each(function ($node) {
|
||||
|
||||
$this->topics[] = [
|
||||
"name" => $node->text(),
|
||||
"slug" => str_replace("https://www.addulive.com/topics/", "", $node->attr('href'))
|
||||
];
|
||||
});
|
||||
|
||||
if($crawler->filter(".author a")->count() == 1)
|
||||
{
|
||||
$this->author = $crawler->filter('.author a')->first()->text();
|
||||
}
|
||||
|
||||
//Remove all the alphabets from string
|
||||
//preg_replace("/[a-zA-Z]/", "",$string);
|
||||
return [
|
||||
'source' => 'Addulive',
|
||||
'title' => $title,
|
||||
'og_title' => $crawler->filter('meta[property*="og:title"]')->first()->attr('content'),
|
||||
'image' => $image,
|
||||
'content' => $this->content,
|
||||
'url' => $url,
|
||||
'date' => $crawler->filter('.entry-meta time')->first()->text(),
|
||||
'guid' => str_replace("https://thepress.mv/","",$url),
|
||||
'author' => $this->author,
|
||||
'topics' => $this->topics
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user