标题: 发个检查链接的代码 很强大 [打印本页] 作者: lingxin5013 时间: 2008-7-23 17:31 标题: 发个检查链接的代码 很强大 set a= Browser("Yahoo!")
set b= Browser("Yahoo!").Page("Yahoo!")
call CheckLinks(a,b)
Function CheckLinks (BrowserObject,BrowserPage)
CheckLinks=TRUE
Dim s_URL,i_CreationTime
Dim s_LinkOuterText,s_LinkInnerText,s_Linkhref
s_URL=BrowserPage.GetROProperty("url")
i_CreationTime=1
i_LinkCount=BrowserPage.object.links.length - 1
Dim i_Link
For i_Link=0 to i_LinkCount
If Trim(BrowserPage.object.links(i_Link).target)="" Then
BrowserPage.object.links(i_Link).target="_blank" ' Set the link to open i a new window so that we dont have any change in current window
End If
BrowserPage.object.links(i_Link).click
On error resume next
Browser("CreationTime:=" & i_CreationTime).sync
Browser("CreationTime:=" & i_CreationTime).Page("micClass:=Page").sync
On error goto 0
Dim s_LinkDetails
IHTML = Browser("CreationTime:=" & i_CreationTime).Page("micClass:=Page").object.Body.innerHTML
'Check if page was not able to be displayed
If (InStr(IHTML,"HTTP 404") <> 0) Or (InStr(IHTML,"cannot be displayed") <> 0) Then
s_LinkDetails="Link Broken" + vbcrlf + "Link Details:" +vbcrlf
s_LinkDetails=s_LinkDetails+"OuterText: "+ s_LinkOuterText + vbcrlf
s_LinkDetails=s_LinkDetails+"InnerText: "+ s_LinkInnerText + vbcrlf
s_LinkDetails=s_LinkDetails+ "href: " + s_Linkhref+ vbcrlf
s_LinkDetails=s_LinkDetails+ "Links Open in New Browse: " & bNewBrowser & vbcrlf
Reporter.ReportEvent micWarning,"Check Link(" & i_Link & ") -> " & s_LinkOuterText ,s_LinkDetails
CheckLinks=FALSE
Else
s_LinkDetails="Link Working" + vbcrlf + "Link Details:" +vbcrlf
s_LinkDetails=s_LinkDetails+"OuterText: "+ s_LinkOuterText + vbcrlf
s_LinkDetails=s_LinkDetails+"InnerText: "+ s_LinkInnerText+ vbcrlf
s_LinkDetails=s_LinkDetails+ "href: " + s_Linkhref+ vbcrlf
s_LinkDetails=s_LinkDetails+ "Links Open in New Browse: " & bNewBrowser & vbcrlf
Reporter.ReportEvent micPass,"Check Link(" & i_Link & ") -> " & s_LinkOuterText ,s_LinkDetails
End If
Browser("CreationTime:=1").close ' Close the link open.
Next
End Function作者: zzfhncn 时间: 2008-7-23 17:42
如果网页中有iframe就检查不到了,呵呵。有高人解决了这个问题了。作者: 假装不在 时间: 2008-7-23 18:11
1,这个做到的是当前页面的检测对吧。没有检测到其它页面的。
还有一点就是少了对frame的检测。