1. 程式人生 > >PHP獲取HTML內容及動態渲染js載入內容 (使用querylist)

PHP獲取HTML內容及動態渲染js載入內容 (使用querylist)

1.安裝

安裝querylist

composer require jaeger/querylist

安裝phantomjs

composer require jaeger/querylist-phantomjs  //PHP版本必須 >=7.0

下載對應你電腦系統的PhantomJS

2.使用

  1. use QL\QueryList;
  2. use QL\Ext\PhantomJs;
  3. $ql =QueryList::getInstance();
  4. // 安裝時需要設定PhantomJS二進位制檔案路徑
  5. $ql->use(PhantomJs::class,'/usr/local/bin/phantomjs');
  6. //or Custom function name
  7. $ql->use(PhantomJs::class,'/usr/local/bin/phantomjs','browser');
  8. // Windows下示例
  9. // 注意:路徑裡面不能有空格中文之類的
  10. $ql->use(PhantomJs::class,'C:/phantomjs/bin/phantomjs.exe');
    1. $html = $ql->browser('https://m.toutiao.com')->getHtml();
    2. print_r($html);