|
这时我上个项目写的一段代码用来检查网页中所有图片是否可达。- Function CheckImages()
- ErrorCount = 0
- Set Objects = myPage.Object.GetElementsByTagName("IMG")
- For Each obj in Objects
- If instr("gif | png | jpg", right(obj.src,3)) >= 1 Then
- ErrorCount = ErrorCount + geturlstatus(obj.src)
- End If
- Next
- Set Objects = myPage.Object.GetElementsByTagName("A")
- For Each obj in Objects
- str = obj.currentstyle.backgroundimage
- If str <> "none" Then
- str = replace(str,left(str,5),"")
- str = replace(str,right(str,2),"")
- ErrorCount = ErrorCount + geturlstatus(str)
- End If
- Next
- If int(ErrorCount) = 0 Then
- CheckImages = "Passed"
- Else
- CheckImages = "Failed("&ErrorCount&")"
- End If
- End Function
复制代码- Public Function GetUrlStatus(url)
- On Error Resume Next
- Set webService = nothing
- Set webService= CreateObject("Microsoft.XMLHTTP")
- webService.open "GET", url, False
- webService.Send
- pagestatus = webService.status
- If pagestatus < 200 or pagestatus >399 Then
- print "The link ["&url&"] is not accessible with error: "& pagestatus
- geturlstatus = 1
- else
- Print "Checking: " & url
- geturlstatus = 0
- 'print "valid request "& pagestatus &" " & url
- End If
- Set webService = nothing
- err.clear
- End Function
复制代码 |
|