Search Engine Result Page Scrapper
This is a work in progress.
Install it using composer: composer require serps/serps
The base package does not include an http client.
We advice you to use our curl client: composer require serps/http-client-curl
The following usage is only a short example, you can check the full documentation.
use Serps\SearchEngine\Google\GoogleClient;
use Serps\HttpClient\CurlClient;
use Serps\SearchEngine\Google\GoogleUrl;
use Serps\Exception\CaptchaException;
use Serps\Exception\RequestErrorException;
$googleClient = new GoogleClient(new CurlClient());
$googleUrl = new GoogleUrl('google.fr');
$googleUrl->setSearchTerm('simpsons');
try {
$googleSerp = $googleClient->query($googleUrl);
$results = $googleSerp->getNaturalResults();
foreach($results as $result){
$resultType = $result->getType();
$resultPosition = $result->getPosition();
// an array of data depending on the result type
$resultData = $result->getData();
}
} catch (CaptchaException $e) {
// Captcha must be solved to continue with this ip
} catch (RequestErrorException $e) {
// Non-captcha error (not found, network error...)
}