PHP :抓取使用 javascript ( ES6 ) 生成的数据
PHP : Scrape data generated with javascript ( ES6 )
我尝试使用 phantomjs 和 php phantomjs 抓取一些 URL 的数据,但是我的目标页面生成了一些使用 ES6 的数据,而 phantomjs 还不支持它,我得到了像这样的一些错误(在控制台日志中):
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 并发布测试版,但它对我不起作用!
现在,我该怎么办?有什么办法可以抓取此页面吗?
虽然 PhantomJS 的未来还不确定,但我可以建议使用另一个无头浏览器:puppeteer。它基于 Google Chrome 无头,背后是一个独立的 Google 工程师团队。
有already projects to control it from PHP, most notable at the moment is puphpeteer*
__
*(值得注意的是它不仅可以screenshots/PDF,而且还提供javascript评价)
我尝试使用 phantomjs 和 php phantomjs 抓取一些 URL 的数据,但是我的目标页面生成了一些使用 ES6 的数据,而 phantomjs 还不支持它,我得到了像这样的一些错误(在控制台日志中):
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 并发布测试版,但它对我不起作用!
现在,我该怎么办?有什么办法可以抓取此页面吗?
虽然 PhantomJS 的未来还不确定,但我可以建议使用另一个无头浏览器:puppeteer。它基于 Google Chrome 无头,背后是一个独立的 Google 工程师团队。
有already projects to control it from PHP, most notable at the moment is puphpeteer*
__
*(值得注意的是它不仅可以screenshots/PDF,而且还提供javascript评价)