PHP:使用javascript生成的数据(ES6)

问题描述 投票:1回答:1

我试图用phantomjs和php phantomjs抓取一些URL的数据,但我的目标页面用ES6生成了一些数据,而phantomjs还不支持它,我得到了一些这样的错误(在Console日志中):

ReferenceError: Can't find variable: Set

我的代码是:

use JonnyW\PhantomJs\Client;

$client = Client::getInstance();

$client->getEngine()->setPath('C:\\Users\\XXX\\Desktop\\bin\\phantomjs.exe');

$request = $client->getMessageFactory()->createRequest('example.com', 'GET');

$response = $client->getMessageFactory()->createResponse();

$client->send($request, $response);
var_dump($response->getConsole());

我搜索了很多!我发现phantomjs将在新版本(v2.5)中支持ES6并发布测试版但它对我不起作用!

现在,我做什么?有没有办法刮掉这个页面?

php phantomjs scrape
1个回答
2
投票

虽然PhantomJS的未来还不确定,但我可以建议使用另一个无头浏览器:puppeteer。它基于谷歌Chrome无头,它背后是一个独立的谷歌工程师团队。

already projects从PHP控制它,目前最值得注意的是puphpeteer *

__ *(值得注意的是它不仅可以制作截图/ PDF,还可以提供javascript评估)

© www.soinside.com 2019 - 2024. All rights reserved.