Add Minoos support
This commit is contained in:
		
							
								
								
									
										48
									
								
								app/Services/Scrapers/MinoosScraper.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										48
									
								
								app/Services/Scrapers/MinoosScraper.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,48 @@ | ||||
| <?php | ||||
|  | ||||
| namespace App\Services\Scrapers; | ||||
|  | ||||
| use Goutte\Client; | ||||
| use Symfony\Component\DomCrawler\Crawler; | ||||
| use Illuminate\Support\Carbon; | ||||
|  | ||||
| class MinoosScraper | ||||
| { | ||||
|     protected $client; | ||||
|  | ||||
|     public function __construct() | ||||
|     { | ||||
|         $this->client = new Client(); | ||||
|     } | ||||
|  | ||||
|     public function extract($url, $date = null, $highlights = null) | ||||
|     { | ||||
|         $crawler = $this->client->request('GET', $url); | ||||
|  | ||||
|         $title = $crawler->filter('h1')->first()->text(); | ||||
|         $content = $crawler->filter('.doc-text')->each(function (Crawler $node) { | ||||
|             return $node->text(); | ||||
|         }); | ||||
|         $image = $crawler->filter('meta[property="og:image"]')->attr('content'); | ||||
|  | ||||
|         $topics = $crawler->filter('a[href^="/tags/"]')->each(function (Crawler $node) { | ||||
|             return [ | ||||
|                 'name' => $node->text(), | ||||
|                 'slug' => str_replace("/tags/", "", $node->attr('href')) | ||||
|             ]; | ||||
|         }); | ||||
|  | ||||
|         return [ | ||||
|             'source'    => 'minoos', | ||||
|             'title'     => $title, | ||||
|             'guid' => basename($url), | ||||
|             'content'   => $content, | ||||
|             'author'    => 'unknown', | ||||
|             'image'     => $image, | ||||
|             'highlights' => $highlights, | ||||
|             'url'       => $url, | ||||
|             'date'      => Carbon::parse($date)->format("Y-m-d H:i:s"), | ||||
|             'topics'      => $topics | ||||
|         ]; | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user