search

Home  >  Q&A  >  body text

php dynamic web crawling

<p>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. </p> <p>This is what I have implemented [I have followed the documentation] -</p> <pre class="brush:php;toolbar:false;">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(); }</pre> <p>It's not returning the title of the URL I'm trying to read. Can you help me debug this issue? </p>
P粉311089279P粉311089279531 days ago608

reply all(1)I'll reply

  • P粉842215006

    P粉8422150062023-09-02 10:50:54

    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();

    reply
    0
  • Cancelreply