PHP獲取HTML內容及動態渲染js載入內容 (使用querylist)
阿新 • • 發佈:2019-01-04
1.安裝
安裝querylist
composer require jaeger/querylist
安裝phantomjs
composer require jaeger/querylist-phantomjs //PHP版本必須 >=7.0
下載對應你電腦系統的PhantomJS
2.使用
use QL\QueryList;
use QL\Ext\PhantomJs;
$ql =QueryList::getInstance();
// 安裝時需要設定PhantomJS二進位制檔案路徑
$ql->use(PhantomJs::class,'/usr/local/bin/phantomjs');
//or Custom function name
$ql->use(PhantomJs::class,'/usr/local/bin/phantomjs','browser');
// Windows下示例
// 注意:路徑裡面不能有空格中文之類的
$ql->use(PhantomJs::class,'C:/phantomjs/bin/phantomjs.exe');
$html = $ql->browser('https://m.toutiao.com')->getHtml();
print_r($html);