i’m trying parse(scrape) the website, and this is my code:
<?php
ini_set('display_errors', 1);
require_once 'vendor/autoload.php';
use FacebookWebDriverRemote{DesiredCapabilities, RemoteWebDriver};
use FacebookWebDriverWebDriverBy;
use FacebookWebDriverWebDriverExpectedCondition;
use FacebookWebDriverExceptionNoSuchElementException;
use FacebookWebDriverExceptionTimeOutException;
// Set up ChromeDriver options
$options = new FacebookWebDriverChromeChromeOptions();
$options->setBinary('/usr/bin/chromium-browser'); // Update with the correct path
$options->addArguments(['--headless']); // Run ChromeDriver in headless mode (optional)
// Start ChromeDriver with the desired capabilities
$capabilities = DesiredCapabilities::chrome();
$capabilities->setCapability(FacebookWebDriverChromeChromeOptions::CAPABILITY, $options);
// Create a new instance of RemoteWebDriver with increased timeout
$driver = RemoteWebDriver::create('http://<vps-ip>:9516/', $capabilities, 60000, '/usr/bin/chromedriver');
// Navigate to the desired website
$driver->get('<url-for-parsing>');
try {
// Wait until the element is visible
$wait = new FacebookWebDriverWebDriverWait($driver, 30);
$element = $wait->until(
WebDriverExpectedCondition::visibilityOfElementLocated(WebDriverBy::xpath('//div[contains(@data-testid, "profile-snippet-name")]'))
);
// Extract the text content of the div element
$divText = $element->getText();
// Print the extracted text
echo $divText;
} catch (NoSuchElementException $e) {
echo "Element not found: " . $e->getMessage();
} catch (TimeOutException $e) {
echo "Timed out waiting for element: " . $e->getMessage();
} finally {
// Quit the driver
$driver->quit();
}
?>
and i’m getting this error:
Fatal error: Uncaught FacebookWebDriverExceptionUnknownServerException: unknown error:
Chrome failed to start: exited abnormally. (unknown error: DevToolsActivePort file doesn't
exist) (The process started from chrome location /usr/bin/chromium-browser is no longer
running, so ChromeDriver is assuming that Chrome has crashed.) (Driver info:
chromedriver=114.0.5735.90 (386bc09e8f4f2e025eddae123f36f6263096ae49-refs/branch-
heads/5735@{#1052}),platform=Linux 5.15.0-75-generic x86_64) in
/home/k/user/user.domain/public_html/app/Http/Controllers/getName/vendor/facebook/webdriver/
lib/Exception/WebDriverException.php:121 Stack trace: #0
/home/kuser/user.domain/public_html/app/Http/Controllers/getName/vendor/facebook/webdriver/l
ib/Remote/HttpCommandExecutor.php(353):
FacebookWebDriverExceptionWebDriverException::throwException(13, 'unknown error: ...',
Array) #1
/home/k/user/user.domain/public_html/app/Http/Controllers/getName/vendor/facebook/webdriver/
lib/Remote/RemoteWebDriver.php(100): FacebookWebDriverRemoteHttpCommandExecutor-
>execute(Object(FacebookWebDriverRemoteWebDriverCommand)) #2
/home/k/user/user.domain/public_html/app/Http/Controllers/getName/index.php(22):
FacebookWebDriverRemoteRemoteWebDriver::create('http://<vps-ip>', Array, 60000,
'/usr/bin/chrome...') #3 {main} thrown in
/home/k/user/user.domain/public_html/app/Http/Controllers/getName/vendor/facebook/webdriver/
lib/Exception/WebDriverException.php on line 121
Note
-
i tried this code on my pc(localhost) it worked, but when i try it on hosting it didn’t work and i got VPS (ubuntu) server and I installed chromium(also google-chrome) browser and chromedriver. I’ m trying to use it but i’m getting this error.
-
All paths (like:
/usr/bin/chromedriver) are given correctly -
the codes that i showed are not localted in vpsm they are located in hosting
-
it’s the 1st time i’m using
chromedriverin php, so please answer detailed
what am i getting when i run chromedriver
root@**:~# chromedriver --port=9516 --whitelisted-ips=""
Starting ChromeDriver 114.0.5735.90 (386bc09e8f4f2e025eddae123f36f6263096ae49-refs/branch-heads/5735@{#1052}) on port 9516
All remote connections are allowed. Use an allowlist instead!
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.


