Update AvasScraper.php
This commit is contained in:
@@ -1,8 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Services\Scrapers;
|
namespace App\Services\Scrapers;
|
||||||
|
|
||||||
use Goutte\Client;
|
use Goutte\Client;
|
||||||
use Illuminate\Support\Carbon;
|
use Illuminate\Support\Carbon;
|
||||||
|
use Exception;
|
||||||
|
|
||||||
class AvasScraper
|
class AvasScraper
|
||||||
{
|
{
|
||||||
@@ -20,30 +22,27 @@ class AvasScraper
|
|||||||
|
|
||||||
public function extract($url, $date)
|
public function extract($url, $date)
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
$crawler = $this->client->request('GET', $url);
|
$crawler = $this->client->request('GET', $url);
|
||||||
|
|
||||||
$title = $crawler->filter('h1')->first()->text();
|
$title = $crawler->filter('h1')->first()->text();
|
||||||
|
|
||||||
if($crawler->filter('figure img')->count() > 0)
|
if ($crawler->filter('figure img')->count() > 0) {
|
||||||
{
|
|
||||||
$this->image = $crawler->filter('figure img')->first()->attr('src');
|
$this->image = $crawler->filter('figure img')->first()->attr('src');
|
||||||
}
|
}
|
||||||
|
|
||||||
if($crawler->filter('.post_content p')->count() == 0)
|
if ($crawler->filter('.post_content p')->count() == 0) {
|
||||||
{
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$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[] = [
|
||||||
@@ -54,8 +53,7 @@ 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();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,9 +68,12 @@ class AvasScraper
|
|||||||
'content' => $this->content,
|
'content' => $this->content,
|
||||||
'url' => $url,
|
'url' => $url,
|
||||||
'date' => $date,
|
'date' => $date,
|
||||||
'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
|
||||||
];
|
];
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user