1.环境要求
采集插件需要安装querylist
PHP >= 7.1
安装querylist只需要在根目录执行下面这条命令就可以了:
composer require jaeger/querylist
时间会有点长 耐心等待
采集默认的是官方portal的应用,可根据自身需求修改model
2.安装步骤
将collect文件夹放入目录public/plugins
后台插件=>安装采集插件=》F5刷新后台 =》插件=》采集管理
3.采集时,内容页URL地址用的是文件缓存,采集完成会释放掉,如果没采集完出错或者人为停止,重新采集时需要后台清除下缓存,否则还是采集上次的地址。
采集多字段数组形式的 假设字段名是value,前台调用遍历$vo.more.value(仅photos还是按照官方的调用(url,name))
例如:
<notempty name="$article.more.value">
<volist name="$article.more.value" id="vo">
<img src="{$vo}"/><br/>
</volist>
</notempty>
采集规则导入示例1:
{"category":"12","name":"17\u7f51","url":"https:\/\/gz.17zwd.com\/sks.htm?so=\u8fde\u8863\u88d9","url_zone":".huohao-list-container .huohao-outside-container .huohao-item","url_prefix":"https:\/\/gz.17zwd.com","url_list_selector":".huohao-list-container .huohao-outside-container .huohao-item .huohao-img-container a","url_list_att":"href","collect_field_liebiao":["post_title","price","thumbnail"],"collect_field_att_liebiao":["title","text","data-original"],"collect_field_selector_liebiao":[".huohao-img-container a",".row-price .price-tag",".huohao-img-container a img"],"collect_field":["post_content"],"collect_field_att":["html"],"collect_field_selector":[".details-right-allTB-image-container"],"collect_multyfield_zone":[".goods-page-small-container .item-small-img-containre a"],"collect_multyfield":["photos"],"collect_multyfield_att":["src"],"collect_multyfield_selector":["img"],"collect_field_tihuan":["photos"],"collect_field_att_tihuan":["50x50"],"collect_field_selector_tihuan":["400x400"],"_plugin":"collect","_controller":"admin_collect","_action":"editpost","collect_fields_tihuan":[{"collect_field_tihuan":"photos","collect_field_att_tihuan":"50x50","collect_field_selector_tihuan":"400x400"}],"collect_fields_liebiao":[{"collect_field_liebiao":"post_title","collect_field_att_liebiao":"title","collect_field_selector_liebiao":".huohao-img-container a"},{"collect_field_liebiao":"price","collect_field_att_liebiao":"text","collect_field_selector_liebiao":".row-price .price-tag"},{"collect_field_liebiao":"thumbnail","collect_field_att_liebiao":"data-original","collect_field_selector_liebiao":".huohao-img-container a img"}],"collect_fields":[{"collect_field":"post_content","collect_field_att":"html","collect_field_selector":".details-right-allTB-image-container"}],"collect_multyfields":[{"collect_multyfield_zone":".goods-page-small-container .item-small-img-containre a","collect_multyfield":"photos","collect_multyfield_att":"src","collect_multyfield_selector":"img"}]}
采集规则导入示例2:
{"category":"16","name":"\u641c\u6b3e\u7f51","url":"https:\/\/www.vvic.com\/gz\/search\/index.html?q=\u8fde\u8863\u88d9","url_zone":".goods-list ul li .item .pic","url_prefix":"https:\/\/www.vvic.com","url_list_selector":"a.j-vda","url_list_att":"href","collect_field":["post_title","post_content","price","thumbnail"],"collect_field_att":["text","html","text","src"],"collect_field_selector":[".product-detail .d-name strong","#descTemplate","strong.d-sale",".tb-pic-main a img"],"collect_multyfield_zone":["#thumblist .tb-thumb-item"],"collect_multyfield":["photos"],"collect_multyfield_att":["src"],"collect_multyfield_selector":["img"],"collect_field_tihuan":["photos"],"collect_field_att_tihuan":["_60x60.jpg"],"collect_field_selector_tihuan":[""],"_plugin":"collect","_controller":"admin_collect","_action":"editpost","collect_fields_tihuan":[{"collect_field_tihuan":"photos","collect_field_att_tihuan":"_60x60.jpg","collect_field_selector_tihuan":""}],"collect_fields":[{"collect_field":"post_title","collect_field_att":"text","collect_field_selector":".product-detail .d-name strong"},{"collect_field":"post_content","collect_field_att":"html","collect_field_selector":"#descTemplate"},{"collect_field":"price","collect_field_att":"text","collect_field_selector":"strong.d-sale"},{"collect_field":"thumbnail","collect_field_att":"src","collect_field_selector":".tb-pic-main a img"}],"collect_multyfields":[{"collect_multyfield_zone":"#thumblist .tb-thumb-item","collect_multyfield":"photos","collect_multyfield_att":"src","collect_multyfield_selector":"img"}]}
4.如果切换模型
php文件里的关键代码替换
adminAddArticle ==》》 adminAddGoods
PortalPostModel ==》》ProductPostModel
app\portal\model\ ==》》app\product\model\
PortalCategoryModel ==》》ProductCategoryModel