分享:怎麼用火車頭採集指定特徵的網址、圖片 src

前些天用火車頭從一個列表頁採集一些網址,源碼簡化如下:

[xhtml] view plain copy

<ahref>111/<ahref>

<ahref>222/<ahref>

<imgsrc>

<ahref>333/<ahref>

我要採集到第二個鏈接,就是鏈接後指定有個IMG的,這個常用來採集熱門帖子等,當時寫的網址採集規則:

[xhtml] view plain copy

<ahref>(*)/<ahref>

<imgsrc>

卻發現怎麼都採集不對,最後想到原因:火車頭從源碼的前面開始匹配,每個鏈接都有

[xhtml] view plain copy

<ahref>[參數]/<ahref>

<imgsrc>

就是把模糊匹配(*)給換成了[參數],就這樣簡單,分享給大家。

大數據觀察