for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace App\Http\Controllers;
use App\Http\Requests;
use Goutte\Client;
class WebScrapingController extends Controller
{
protected $crawler;
const NEWS_URL = 'https://news.ycombinator.com/';
/**
* Initialize controller
*/
public function __construct()
$this->client = new Client();
client
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
class MyClass { } $x = new MyClass(); $x->foo = true;
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:
class MyClass { public $foo; } $x = new MyClass(); $x->foo = true;
}
* Return all data to the Stripe API dashboard
* @return mixed
public function getPage()
$links = $this->getData(self::NEWS_URL);
return view('api.scraping')->withLinks($links);
* Scrape the Links
* @param $siteToCrawl
* @return array
public function getData($siteToCrawl)
$crawler = $this->client->request('GET', $siteToCrawl);
$arr = $crawler->filter('.title a[href^="http"], a[href^="https"]')->each(function($element) {
$links = [];
array_push($links, $element->text());
return $links;
});
return $arr;
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: