php dynamic web crawling
P粉311089279
2023-09-01 18:42:58
<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>
Before making modifications, put this in your script so that it displays the error:
The error may lie in this line: This method does not accept strings.
You must pass the google chrome executable to:
Or leave it blank and the system will use the default location: