-
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.
Add missing web crawler template file
- Loading branch information
Showing
1 changed file
with
63 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands; | ||
|
||
use Illuminate\Console\Command; | ||
use Symfony\Component\Panther\Client; | ||
|
||
class NewCrawler2024 extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'command:name'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Command description'; | ||
|
||
/** | ||
* @var Client | ||
*/ | ||
private Client $client; | ||
|
||
public function __construct() | ||
{ | ||
parent::__construct(); | ||
$this->client = Client::createSeleniumClient( | ||
'http://localhost:'.config('app.selenium_grid_port').'/wd/hub' | ||
); | ||
} | ||
|
||
/** | ||
* @return void | ||
*/ | ||
private function getInput() { | ||
$words = $this->ask('>>'); | ||
$this->info($words); | ||
} | ||
|
||
/** | ||
* Execute the console command. | ||
* | ||
* @return int | ||
*/ | ||
public function handle() | ||
{ | ||
$this->client | ||
->get('https://www.imdb.com/search/name/?birth_monthday=12-10'); | ||
$crawler = $this->client->getCrawler(); | ||
$preferences = $crawler->filterXPath('//button[@data-testid="accept-button"]'); | ||
$preferences->click(); | ||
$element = $crawler->filterXPath('//h3[text()="1. Kenneth Branagh"]'); | ||
$element->click(); | ||
$this->client->takeScreenshot($saveAs = 'screenshot.jpg'); | ||
|
||
return 0; | ||
} | ||
} |