-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
01f9ad0
commit 9b0242a
Showing
36 changed files
with
1,173 additions
and
490 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
vendor | ||
exemplo | ||
.vscode | ||
.vscode | ||
coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
|
||
|
||
# Executar Selenium | ||
|
||
docker run --rm --net=host -p 4444:4444 -p 7900:7900 --shm-size="2g" selenium/standalone-chrome:latest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace ScraPHP\HttpClient; | ||
|
||
use Psr\Log\LoggerInterface; | ||
use GuzzleHttp\Exception\ClientException; | ||
use GuzzleHttp\Exception\ConnectException; | ||
use ScraPHP\Exceptions\HttpClientException; | ||
use ScraPHP\Exceptions\AssetNotFoundException; | ||
|
||
final class AssetFetcher | ||
{ | ||
|
||
private \GuzzleHttp\Client $client; | ||
|
||
public function __construct( | ||
private LoggerInterface $logger, | ||
){ | ||
$this->client = new \GuzzleHttp\Client(); | ||
} | ||
|
||
/** | ||
* Fetches an asset from the given URL. | ||
* | ||
* @param string $url The URL of the asset. | ||
* @return string The contents of the asset. | ||
* | ||
* @throws AssetNotFoundException If the asset could not be found. | ||
*/ | ||
public function fetchAsset(string $url): string | ||
{ | ||
try { | ||
$this->logger->info('Fetching asset '.$url); | ||
$response = $this->client->request('GET', $url); | ||
$this->logger->info('Status: '.$response->getStatusCode().' '.$url); | ||
} catch (ClientException $e) { | ||
if ($e->getCode() === 404) { | ||
$this->logger->error('404 NOT FOUND '.$url); | ||
throw new AssetNotFoundException($url.' not found'); | ||
} | ||
} catch(ConnectException $e) { | ||
throw new HttpClientException($e->getMessage(), $e->getCode(), $e); | ||
} | ||
|
||
return $response->getBody()->getContents(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace ScraPHP\HttpClient; | ||
|
||
interface FilteredElement | ||
{ | ||
public function text(): string; | ||
|
||
public function attr(string $attr): ?string; | ||
|
||
public function filterCSS(string $cssSelector): ?FilteredElement; | ||
|
||
public function filterCSSEach(string $cssSelector, callable $callback): array; | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.