Update AvasScraper.php
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Services\Scrapers;
|
namespace App\Services\Scrapers;
|
||||||
|
|
||||||
use Goutte\Client;
|
use Goutte\Client;
|
||||||
@@ -11,7 +12,7 @@ class AvasScraper
|
|||||||
protected $content;
|
protected $content;
|
||||||
protected $author;
|
protected $author;
|
||||||
protected $topics = [];
|
protected $topics = [];
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->client = new Client;
|
$this->client = new Client;
|
||||||
@@ -26,17 +27,16 @@ class AvasScraper
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
$image = $crawler->filter('figure img')->first()->attr('src');
|
$image = ($crawler->filter('figure img')->first()->attr('src')) ? $crawler->filter('figure img')->first()->attr('src') : "/images/noimg.jpg";
|
||||||
|
|
||||||
$crawler->filter('.post_content p')->each(function ($node) {
|
$crawler->filter('.post_content p')->each(function ($node) {
|
||||||
$this->content[] = preg_replace("/[a-zA-Z]/","",$node->text());
|
$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) {
|
$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
|
//Removing the show more tags button
|
||||||
if($node->text() == "+")
|
if ($node->text() == "+") {
|
||||||
{
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$this->topics[] = [
|
$this->topics[] = [
|
||||||
@@ -45,17 +45,16 @@ class AvasScraper
|
|||||||
];
|
];
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if($crawler->filter('div[class*="font-waheed text-grey ml-3 pl-3 text-lg border-l border-grey border-dotted"] a')->count() == 1)
|
|
||||||
{
|
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();
|
$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
|
//Remove all the alphabets from string
|
||||||
//preg_replace("/[a-zA-Z]/", "",$string);
|
//preg_replace("/[a-zA-Z]/", "",$string);
|
||||||
return [
|
return [
|
||||||
'source' => 'Avas',
|
'source' => 'Avas',
|
||||||
'title' => $title,
|
'title' => $title,
|
||||||
'og_title' => $crawler->filter('meta[property*="og:title"]')->first()->attr('content'),
|
'og_title' => $crawler->filter('meta[property*="og:title"]')->first()->attr('content'),
|
||||||
@@ -63,9 +62,9 @@ class AvasScraper
|
|||||||
'content' => $this->content,
|
'content' => $this->content,
|
||||||
'url' => $url,
|
'url' => $url,
|
||||||
'date' => Carbon::parse($crawler->filter('timeago')->first()->attr('datetime'))->format("Y-m-d H:i:s"),
|
'date' => Carbon::parse($crawler->filter('timeago')->first()->attr('datetime'))->format("Y-m-d H:i:s"),
|
||||||
'guid' => str_replace("https://avas.mv/","",$url),
|
'guid' => str_replace("https://avas.mv/", "", $url),
|
||||||
'author' => $this->author,
|
'author' => $this->author,
|
||||||
'topics' => $this->topics
|
'topics' => $this->topics
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user