diff options
author | Fbenas <philbeansburton@gmail.com> | 2020-06-19 02:16:51 +0100 |
---|---|---|
committer | Fbenas <philbeansburton@gmail.com> | 2020-06-19 02:16:51 +0100 |
commit | d1fe4536cc039450b540104e382db0d01d5cf886 (patch) | |
tree | fd40ab48f79370541f377b59bb381811126485ad /app/Console/Commands/ScrapeUrl.php | |
parent | c83e876693bdb71c66418c13f5e09dfdaef24478 (diff) |
Initial commit
Diffstat (limited to 'app/Console/Commands/ScrapeUrl.php')
-rw-r--r-- | app/Console/Commands/ScrapeUrl.php | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/app/Console/Commands/ScrapeUrl.php b/app/Console/Commands/ScrapeUrl.php new file mode 100644 index 0000000..c02080e --- /dev/null +++ b/app/Console/Commands/ScrapeUrl.php @@ -0,0 +1,61 @@ +<?php + +namespace App\Console\Commands; + +use Illuminate\Console\Command; +use Goutte\Client; + +class ScrapeUrl extends Command +{ + /** + * The name and signature of the console command. + * + * @var string + */ + protected $signature = 'scrape:url { url }'; + + /** + * The console command description. + * + * @var string + */ + protected $description = 'Scrape a webpage for data'; + + protected $client; + + /** + * Create a new command instance. + * + * @return void + */ + public function __construct() + { + parent::__construct(); + $this->client = new Client(); + } + + /** + * Execute the console command. + * + * @return mixed + */ + public function handle() + { + $url = $this->argument('url'); + + if ($url != 'https://www.sixnationsrugby.com/fixtures/') { + $this->error('Url not supported'); + return; + } + + $crawler = $this->client->request('GET', $this->argument('url')); + + $crawler->filter('div.fixtures__top-tier')->each( + function ($node) { + print $node->text()."\n"; + } + ); + + + } +} |