QueryList采集器開發(fā)手冊(cè)
/ DImage 圖片下載擴(kuò)展
DImage 圖片下載擴(kuò)展
DImage圖片下載擴(kuò)展
DImage擴(kuò)展,可實(shí)現(xiàn)簡單的圖片下載需求。
安裝:
composer require jaeger/querylist-ext-dimage
GIT地址:
https://github.com/jae-jae/QueryList-Ext-DImage
依賴(通過Composer安裝的請(qǐng)忽略)
DImage擴(kuò)展依賴Http
類,Git地址為:https://github.com/jae-jae/Http.git
手動(dòng)安裝插件教程:http://doc.querylist.cc/site/index/doc/7
用法一
<?php require 'querylist/vendor/autoload.php'; use QL\QueryList; $html = QueryList::run('DImage',[ //html內(nèi)容 'content' => file_get_contents('http://xxx.com/1.html'), //圖片保存路徑(相對(duì)于網(wǎng)站跟目錄),可選,默認(rèn):/images 'image_path' => '/xx/x/', //網(wǎng)站根目錄全路徑,如:/var/www/html 'www_root' => dirname(__FILE__), //補(bǔ)全HTML中的圖片路徑,可選,默認(rèn)為空 'base_url' => 'http://uploads.rayli.com.cn', //圖片鏈接所在的img屬性,可選,默認(rèn)src //多個(gè)值的時(shí)候用數(shù)組表示,越靠前的屬性優(yōu)先級(jí)越高 'attr' => array('data-src','src'), //單個(gè)值時(shí)可直接用字符串 //'attr' => 'data-src', //回調(diào)函數(shù),用于對(duì)圖片的額外處理,可選,參數(shù)為img的phpQuery對(duì)象 'callback' => function($imgObj){ $imgObj->attr('alt','xxx'); $imgObj->removeAttr('class'); //...... } ]); print_r($html);
用法二
$url = 'http://cms.querylist.cc/news/it/547.html'; $reg = [ 'title' => array('h1','text'), 'content' => array('.post_content','html') ]; $data = QueryList::Query($url,$reg,'.content')->getData(function($item){ //圖片本地化 $item['content'] = QueryList::run('DImage',[ 'content' => $item['content'], 'image_path' => '/img/'.date('Y-m-d'), 'www_root' => dirname(__FILE__) ]); return $item; }); print_r($data);
用法三
<?php require 'querylist/vendor/autoload.php'; use QL\QueryList; $con =<<<STR <img src="/App/Tpl/Home/images/loading.gif" data-original="/images/896891/c21alNoWfSAJ6xqN44SRAdW+0M3gZ7H3msPj8/SpdYZXnUZprQ1Xg5IxQcARLus6wz9xz5O7xve82KY2dpmEGjuLP49w.jpg" alt="鮭魚龍蝦魚子醬" class="img-responsive img-thumbnail lazy"> <br/> <img src="/App/Tpl/Home/images/loading.gif"> STR; $html = QueryList::run('DImage',[ 'content' => $con, 'www_root' => dirname(__FILE__), 'base_url' => 'http://x.44i.cc', 'attr' => array('data-original','src'), 'image_path' => '/xx', 'callback' => function($o){ $o->attr('alt','111'); $o->removeAttr('class'); } ]); echo $html; /** 輸出: <img src="/App/Tpl/Home/images/loading.gif" data-original="/xx/fd0c11eef490f3b215a050ac0b9a1318.jpg" alt="111"><br><img src="/xx/a2b617f74ce48ef9d88bfeb96443010b.gif" alt="111"> **/