1. Go to this page and download the library: Download aktuba/php-puppeteer library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use Puphpeteer\Puppeteer;
use Puphpeteer\Data\Js;
$puppeteer = new PhpPupeeteer;
$browser = $phpPuppeteer->getBrowser();
$page = $browser->newPage();
$page->gotoWithWait('https://example.com');
// Get the "viewport" of the page, as reported by the page.
$dimensions = $page->evaluate(Js::createWithBody("
return {
width: document.documentElement.clientWidth,
height: document.documentElement.clientHeight,
deviceScaleFactor: window.devicePixelRatio,
};
"));
printf('Dimensions: %s', print_r($dimensions, true));
$browser->close();
use PhpPupeeteer\PhpPupeeteer;
$puppeteer = PhpPupeeteer;
[
// Logs the output of Browser's console methods (console.log, console.debug, etc...) to the PHP logger
'log_browser_console' => false,
]
$phpPuppeteer = $phpPuppeteer->getBrowser([
'read_timeout' => 65, // In seconds
]);
$browser->newPage()->goto($url, [
'timeout' => 60000, // In milliseconds
]);
$divs = $page->querySelectorAll('div');
use PhpPupeeteer\Data\Js;
$pageFunction = Js::createWithParameters(['element'])
->body("return element.textContent")
;
use Nesk\Rialto\Exceptions\Node;
try {
$page->tryCatch->goto('invalid_url');
} catch (Node\Exception $exception) {
// Handle the exception...
}
shell
composer nesk/puphpeteer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.