Skip to content
This repository has been archived by the owner on Sep 12, 2021. It is now read-only.

Commit

Permalink
detect cloudflare protection
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukas Alexander Kienzl committed May 21, 2018
1 parent 5ddf07c commit c4c5f81
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/ChromeHeadless.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace ChromeHeadless;

use ChromeHeadless\Exceptions\CloudflareProtection;
use Symfony\Component\Process\Process;
use Symfony\Component\DomCrawler\Crawler;
use ChromeHeadless\Exceptions\EmptyDocument;
Expand Down Expand Up @@ -59,6 +60,10 @@ public function setHtml(string $html)
throw new EmptyDocument($this->url);
}

if (strpos($html, 'cf-browser-verification cf-im-under-attack') !== false) {
throw new CloudflareProtection($this->url);
}

$this->html = $html;

return $this;
Expand Down
13 changes: 13 additions & 0 deletions src/Exceptions/CloudflareProtection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace ChromeHeadless\Exceptions;

use Exception;

class CloudflareProtection extends Exception
{
public function __construct($url)
{
parent::__construct("Could not get `${url}`. This website is protected by Cloudflare.");
}
}

0 comments on commit c4c5f81

Please sign in to comment.