php dynamic web crawling
P粉311089279
P粉311089279 2023-09-01 18:42:58
0
1
461

I'm trying the chrome-php/chrome library to read dynamically rendered web pages, but it's not returning anything. I'm using php version 8.0.

This is what I have implemented [I have followed the documentation] -

use HeadlessChromium\BrowserFactory; $browserFactory = new BrowserFactory(); // starts headless chrome $browser = $browserFactory->createBrowser('/opt/google/chrome/chrome'); try { // creates a new page and navigate to an URL $page = $browser->createPage(); $page->navigate('http://example.com')->waitForNavigation(); // get page title $pageTitle = $page->evaluate('document.title')->getReturnValue(); echo $pageTitle; } finally { //bye $browser->close(); }

It's not returning the title of the URL I'm trying to read. Can you help me debug this issue?

P粉311089279
P粉311089279

reply all (1)
P粉842215006

Before making modifications, put this in your script so that it displays the error:

ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL);

The error may lie in this line: This method does not accept strings.

$browser = $browserFactory->createBrowser('/opt/google/chrome/chrome');

You must pass the google chrome executable to:

$browserFactory = new BrowserFactory('/opt/google/chrome/chrome');

Or leave it blank and the system will use the default location:

$browserFactory = new BrowserFactory();
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!