Skip to content

Commit

Permalink
Add missing web crawler template file
Browse files Browse the repository at this point in the history
  • Loading branch information
kkamara committed Mar 16, 2024
1 parent 3a3a922 commit 0604f85
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions storage/app/NewCrawler2024.php
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;
}
}

0 comments on commit 0604f85

Please sign in to comment.