火車採集器使用PHP插件配置循環標籤的方法

*參數說明:
*LabelArray - 標籤名及標籤內容集合 結構如:Array('欄目id' => 2,'出處'=> '新浪微博','內容'=>'<center><b>暴笑短信') ## *LabelUrl - 當前採集的頁面的Url地址
*$LabelCookie - 當前採集頁面,服務器返回的Cookie信息。

  • 特別注意:如果是處理列表頁,默認頁,多頁時會有以下兩個標籤
    LabelArray['Html'] 網頁的源代碼,沒有經過採集器處理的,直接下載後的數據.修改這裏的數據,請將新值賦予LabelArray['Html']
    $LabelArray['PageType'] 值可能爲 List, Content ,Pages, Save 分別代表處理列表頁,默認頁,多頁,保存時
    • List 列表頁
    • Content 默認頁
    • Pages 多頁
    • Save 保存時

根據以上參數可以推斷,我們需要在$LabelArray['Html'] 中對原標籤進行處理

例如(替換):
插件中:
if(LabelArray['PageType']=="List"){} else if(LabelArray['PageType']=="Content")
{
LabelArray['Html'] = str_replace('<title>','<title>新字符串</title><title>新字符串</title><title>新字符串</title>',LabelArray['Html']);
}
else if(LabelArray['PageType']=="Save"){} 在採集器中: ![image.png](https://upload-images.jianshu.io/upload_images/15191413-ddec8fa6034ec42e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) 可見採集器中有多條記錄 ![image.png](https://upload-images.jianshu.io/upload_images/15191413-8ce6cee0ae657eb1.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) 例如2(新增標籤): foreach (JsonData[initDataObj][goods][skus] as sku) {specs = sku[specs];//屬性normalPrice = sku[normalPrice];//單價groupPrice = sku[groupPrice];//拼團價skuId = sku[skuId];//skuIdshuxing = "";
foreach (specs asspec) {
spe = '<span>屬性:'.spec[spec_key].'</span><span>:'.spec[spec_value].'</span>';shuxing = shuxing.spe;
}
tag = '<div class="sku">'.shuxing.'</span><span>單價:'.sku[normalPrice].'</span><span>拼團價:'.sku[groupPrice].'</span><span>skuId:'.sku[skuId].'</span><div>';LabelArray['Html']='<test>'.tag.'</test>'.LabelArray['Html'];
}

遇到的坑:

測試時在else if(LabelArray['PageType']=="Content") 中處理正常使用 實際運行則需要在 if(LabelArray['PageType']=="List")中處理

一個插件文件需要在對應的配置中選擇纔會執行,例如插件有請求處理,結果處理,但是火車頭配置中至選了結果處理插件,則請求的部分不會執行

                                 交流採集技術可加微信:flutter_code  聯繫我
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章