ASP獲取網(wǎng)頁(yè)全部圖片地址并保存為數(shù)組的正則
當(dāng)前位置:點(diǎn)晴教程→知識(shí)管理交流
→『 技術(shù)文檔交流 』
ASP獲取網(wǎng)頁(yè)全部圖片地址并保存為數(shù)組的正則 目前還是有BUG的,最新的測(cè)試頁(yè)面在: http://www.reallydo.com/getimg.asp
jsp分析頁(yè)面在: http://jorkin.reallydo.com/article.asp?id=380 發(fā)現(xiàn)BUG請(qǐng)?jiān)诤竺媪粞?謝謝. 1.31修正 src=后面有空格不能正確匹配.已修正. src=''為空時(shí)出錯(cuò).已修正. 發(fā)現(xiàn)BUG: 圖片路徑有多個(gè)空格時(shí)只能保留一個(gè).未修正. 2.18修正 圖片路徑有多個(gè)空格時(shí)只能保留一個(gè)的BUG.已修正. 復(fù)制代碼 代碼如下: <% '功能:獲取全部圖片地址,保存到一個(gè)數(shù)組. '來(lái)源:http://jorkin.reallydo.com/article.asp?id=448 '需要ReplaceAll函數(shù):http://jorkin.reallydo.com/article.asp?id=406 Function getIMG(sString) Dim sReallyDo, regEx, iReallyDo Dim oMatches, cMatch '//定義一個(gè)空數(shù)組 iReallyDo = -1 ReDim aReallyDo(iReallyDo) If IsNull(sString) Then getIMG = "" Exit Function End If '//格式化HTML代碼 '//將每個(gè) <img 換行 方便jsp替換 sReallyDo = sString On Error Resume Next sReallyDo = Replace(sReallyDo, vbCr, " ") sReallyDo = Replace(sReallyDo, vbLf, " ") sReallyDo = Replace(sReallyDo, vbTab, " ") sReallyDo = Replace(sReallyDo, "<img ", vbCrLf & "<img ", 1, -1, 1) sReallyDo = Replace(sReallyDo, "/>", " />", 1, -1, 1) sReallyDo = ReplaceAll(sReallyDo, "= ", "=", True) sReallyDo = ReplaceAll(sReallyDo, "> ", ">", True) sReallyDo = Replace(sReallyDo, "><", ">" & vbCrLf & "<") sReallyDo = Trim(sReallyDo) On Error GoTo 0 Set regEx = New RegExp regEx.IgnoreCase = True regEx.Global = True '//去除onclick,onload等腳本 regEx.Pattern = "\s[on].+?=([\""|\'])(.*?)\1" sReallyDo = regEx.Replace(sReallyDo, "") '//將SRC不帶引號(hào)的圖片地址加上引號(hào) regEx.Pattern = "<img.*?\ssrc=([^\""\'\s][^\""\'\s>]*).*?>" sReallyDo = regEx.Replace(sReallyDo, "<img src=""$1"" />") '//jsp匹配圖片SRC地址 regEx.Pattern = "<img.*?\ssrc=([\""\'])([^\""\']+?)\1.*?>" Set oMatches = regEx.Execute(sReallyDo) '//將圖片地址存入數(shù)組 For Each cMatch in oMatches iReallyDo = iReallyDo + 1 ReDim Preserve aReallyDo(iReallyDo) aReallyDo(iReallyDo) = regEx.Replace(cMatch.Value, "$2") Next getIMG = aReallyDo End Function %> 該文章在 2011/2/16 11:46:43 編輯過(guò) |
關(guān)鍵字查詢
相關(guān)文章
正在查詢... |