如何使用V8JS渲染网站?

时间:2019-06-12 01:45:26

标签: php v8js

我试图了解V8JS的工作原理,我进行了测试,但没有成功。

我想呈现此站点https://react.rocks/,然后使用DOMDocument。

所以我做到了:

$url = 'https://react.rocks/';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,  true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$file = curl_exec($ch);

$dom = new DOMDocument;
$dom->loadHTML($file);
$v8 = new V8Js();

foreach( $dom->getElementsByTagName('script') as $script){

    $v8->executeString($script->nodeValue);
}
$exec = file_get_contents('https://react.rocks/scripts/bundle.js');
$v8->executeString($exec);

echo $file;

我有这个回报

Uncaught exception 'V8JsScriptException' with message 'V8Js::compileString():2: ReferenceError: window is not defined' in info.php:18 Stack trace: #0 info.php(18): V8Js->executeString('var z={accessTo...') #1 {main} thrown in

0 个答案:

没有答案