PuPHPEteer is a powerful bridge that connects the world of Puppeteer with PHP, enabling developers to leverage the extensive capabilities of Puppeteer within a PHP environment.
This tool is built on top of Rialto, a package designed to manage Node resources from PHP.
Table of contents:
PuPHPEteer can be installed via Composer. Make sure you have PHP and Node.js installed on your system.
composer require zoon/puphpeteer
PuPHPEteer can be used to perform a variety of tasks, such as navigating to web pages, taking screenshots, and executing scripts within the context of a web page. Below are a couple of examples demonstrating its usage.
The following example demonstrates how to navigate to a web page and save a screenshot.
use Nesk\Puphpeteer\Puppeteer;
$puppeteer = new Puppeteer;
$browser = $puppeteer->launch();
$page = $browser->newPage();
$page->goto('https://example.com');
$page->screenshot(['path' => 'example.png']);
$browser->close();
This example shows how to evaluate a script in the context of a page.
use Nesk\Puphpeteer\Puppeteer;
use Nesk\Rialto\Data\JsFunction;
$puppeteer = new Puppeteer;
$browser = $puppeteer->launch();
$page = $browser->newPage();
$page->goto('https://example.com');
// Get the "viewport" of the page, as reported by the page.
$dimensions = $page->evaluate(JsFunction::createWithBody("
return {
width: document.documentElement.clientWidth,
height: document.documentElement.clientHeight,
deviceScaleFactor: window.devicePixelRatio
};
"));
echo 'Dimensions: ' . json_encode($dimensions);
$browser->close();
Beyond basic navigation and script evaluation, PuPHPEteer supports more advanced functionalities such as handling authentication, manipulating the DOM, and interacting with various elements on a page.
You can use PuPHPEteer to handle basic authentication.
$page->authenticate([
'username' => 'myUsername',
'password' => 'myPassword'
]);
$page->goto('https://example.com/secure');
Interact with elements on the page by using methods like $page->click()
, $page->type()
, and more.
$page->goto('https://example.com');
$page->type('#search', 'puppeteer');
$page->click('#search_button');
$page->waitForNavigation();
After loading a website, you have access to all elements in DOM.
You can get information using querySelector
, or querySelectorAll
. Here is a simple example:
$company_elements = $page->querySelectorAll('.company');
foreach ($company_elements as $company_element) {
// select the name and address elements
$name_element = $company_element->querySelector('h2');
$address_element = $company_element->querySelector('p');
// retrieve the data of interest
$name = $name_element->evaluate(JsFunction::createWithParameters(['node'])->body('return node.innerText;'));
$address = $address_element->evaluate(JsFunction::createWithParameters(['node'])->body('return node.innerText;'));
// create a new company object and add it to the list
$company = ['name' => $name, 'address' => $address];
$companies[] = $company;
}
PuPHPEteer extends the powerful capabilities of Puppeteer to PHP developers, enabling them to automate web tasks efficiently within their preferred programming environment. Whether it's for testing, web scraping, or automation, PuPHPEteer offers a versatile and robust solution for your PHP applications.
For more information, visit the official repository.
By leveraging PuPHPEteer, developers can harness the full power of Puppeteer while working within a PHP ecosystem, making it a valuable tool for a wide range of web automation tasks.
Do you own a company or need help with your Laravel project? I can help you with that. Check the plans and let me know if you have any questions.
Get 1 month free with yearly plan during checkout.
$ 3 ,995
/m
What's included:
$ 5 ,995
/m
What's included:
Ok, just book a call now.
Good question! For starters, the annual cost of a full-time senior-level developer now exceeds $100,000, plus benefits (and good luck finding one available).
Aside from that, you may not always have enough work to keep them busy at all times, so you're stuck paying for time you aren't able to utilize.
With the monthly plan, you can pause and resume your subscription as often as you need to ensure you're only paying your developer when you have work available for them.
No, once subscribed you're able to request as many things as you'd like, and they will be delivered one by one.
Delivery will always be fast without compromising quality. Very complex requests will be divided into smaller products for continuous delivery.
Always, before starting to work, we can make a planning so that you know, before starting, when each change will be delivered.
You'll work directly with me, the founder and only person behind DeveloperJoy.
We understand you may not have enough work to fill up entire month. Perhaps you only have one or two requests at the moment. That's where pausing your subscription comes in handy.
Billing cycles are based on 31 day period. Let's say you sign up and use the service for 21 days, and then decide to pause your subscription. This means that the billing cycle will be paused and you'll have 10 days of service remaining to be used anytime in the future
I had experience making products with PHP, Go, and JavaScript/TypeScript.
Also I feel really comfortable working with WordPress, Laravel, Symfony, Vue.js, React, Svelte, and more.
Mail me and we will see how best to collaborate.
You can make this request by email, sharing a task board with me or, depending on your plan, by call or Slack.
That's fine. You can pause your subscription when finished and return when you have additional requests needs. There's no need to let the remainder of your subscription go to waste.
Due to the high quality nature of the work, there will be no refunds issued.