<%
Class Spider
Private gblTxt, gblTmp, strPath, bMinimal
Private Sub Class_Initialize()
gblTmp = ""
gblTxt = ""
strPath = ""
bMinimal = False
End Sub
Private Sub Class_Terminate()
gblTmp = ""
gblTxt = ""
strPath = ""
End Sub
Private Function GetWebPage(byVal address)
Dim Fetch
On Error Resume Next
Set Fetch = GetObject("java:HTTPFetch")
If Err Then
Err.Clear
GetWebPage = Null
Exit Function
End If
On Error GoTo 0
GetWebPage = UCase( Trim( Fetch.GetURL(address) ) )
Set Fetch = Nothing
End Function
Private Function SrchNDisplay(byVal EraseSrchCriteria, byval intInc, _
byVal Criteria1, byVal Criteria2)
Dim strSt, tmp
Select Case CBool( EraseSrchCriteria )
Case True
strSt = InStr( gbltxt, Criteria1 ) + intInc
tmp = Mid( gbltxt, strSt, InStr( _
strSt, gbltxt, Criteria2 ) _
- strSt )
Case False
strSt = InStr( gbltxt, Criteria1 )
tmp = Mid( gbltxt, strSt, InStr( _
strSt, gbltxt, Criteria2 ) _
- strSt + intInc)
End Select
SrchNDisplay = tmp
End Function
Private Sub RdMeta(byval lngStart, byval strHeaderTxt)
dim secStart, strTmp
On Error Resume Next
lngStart = InStr( lngStart, strHeaderTxt, "<META " )
secStart = InStr( lngStart + 5, strHeaderTxt, ">" )
if lngStart = 0 then RdMeta = "" : Exit Sub
strTmp = Mid( strHeaderTxt, lngStart , _
secStart - lngStart + 1) & vbCrLf
If Err Then Exit Sub
On Error GoTo 0
gblTmp = gblTmp & strTmp & "/|\"
Call RdMeta( secStart, strHeaderTxt )
End Sub
Private Function FixTag(byVal indTag)
dim strInc
strInc = Mid( indTag, InStr( indTag, chr(34) ) + 1 )
if len( strInc ) > 0 then _
strInc = Left( strInc, Len( strInc ) - 1 )
FixTag = Replace( strInc, chr(34), "" )
End Function
Private Function GetTagName(byVal dirtytag)
dim a, b
On Error Resume Next
if instr( dirtytag, chr(34) ) then
a = inStr( dirtytag, "NAME=" & chr(34) )
b = instr( a + 6, dirtytag, chr(34) & " " )
if a = 0 then
a = inStr( dirtytag, "NAME = " & chr(34) )
end if
else
' if no "'s are found
a = inStr( dirtytag, "NAME=" )
b = instr( a + 5, dirtytag, " " )
end if
GetTagName = Mid( dirtytag, a, b - a + 1 )
If Err Then
if instr( dirtytag, chr(34) ) then
a = inStr( dirtytag, "EQUIV=" & chr(34) )
b = instr( a + 7, dirtytag, chr(34) & " " )
if a = 0 then
a = inStr( dirtytag, "EQUIV = " & chr(34) )
end if
else
' if no "'s are found
a = inStr( dirtytag, "EQUIV=" )
b = instr( a + 6, dirtytag, " " )
end if
Else
Exit Function
End If
GetTagName = ""
GetTagName = Mid( dirtytag, a, b - a + 1 )
On Error GoTo 0
End Function
Private Function GetTagValue(byVal dirtytag)
dim a, b
dirtytag = UCASE( dirtytag )
if instr( dirtytag, chr(34) ) then
a = inStr( dirtytag, "CONTENT=" & chr(34) )
b = instr( a + 9, dirtytag, chr(34) & ">" )
if a = 0 then
a = inStr( dirtytag, "CONTENT = " & chr(34) )
b = instr( a + 9, dirtytag, chr(34) & ">" )
end if
elseif instr( dirtytag, chr(39) ) then
a = inStr( dirtytag, "CONTENT=" & chr(39) )
b = instr( a + 9, dirtytag, chr(39) & ">" )
end if
if b = 0 then
GetTagValue = Mid( dirtytag, a )
elseif a = 0 then
GetTagValue = Mid( dirtytag, 1, b )
else
GetTagValue = Mid( dirtytag, a, b - a + 1 )
end if
End Function
Public Default Sub Retrieve(byval HTTPpath)
bMinimal = True
strPath = HTTPpath
gblTxt = Trim( UCase( GetWebPage( HTTPpath ) ) )
If IsNull( gblTxt ) Then
Err.Raise 5175, "Spider Class", _
"Web Page Cannot Be Retrieved."
End If
End Sub
Public Function PageTitle()
If NOT bMinimal Then RetrieveError()
PageTitle = Trim( SrchNDisplay(True, 7, _
"<TITLE>", "</TITLE>") )
End Function
Public Function RawHeader()
If NOT bMinimal Then RetrieveError()
RawHeader = Trim( SrchNDisplay(False, 7, _
"<HEAD>", "</HEAD>") )
End Function
Public Function RawBody()
If NOT bMinimal Then RetrieveError()
RawBody = Trim( SrchNDisplay(False, 7, _
"<BODY", "</BODY>") )
End Function
Public Function RawMetaTags()
If NOT bMinimal Then RetrieveError()
Dim strTmp, max, i
Call RdMeta( 1, RawHeader )
strTmp = Split( gblTmp, "/|\" )
max = ubound(strTmp) - 1
Redim Preserve strTmp(max)
for i = 0 to ubound(strTmp)
strTmp(i) = Trim( Replace( Replace( _
strTmp(i), vbCrLf, ""), vbTab, "" ) )
next
RawMetaTags = strTmp
End Function
Public Property GET PageAddress()
If NOT bMinimal Then RetrieveError()
PageAddress = Trim( UCase( strPath ) )
End Property
Public Function MetaTagPairs()
If NOT bMinimal Then RetrieveError()
Dim tmp, item, dic, a, b, i
Dim outarray()
tmp = RawMetaTags
Set dic = CreateObject("scripting.dictionary")
on error resume next
for each item in tmp
dic.add FixTag( GetTagName( item ) ), _
FixTag( GetTagValue( item ) )
next
on error goto 0
a = dic.keys
b = dic.items
Redim outarray( 1, dic.count - 1 )
for i = 0 to dic.count - 1
outarray(0, i) = a(i)
outarray(1, i) = b(i)
next
set dic = Nothing
MetaTagPairs = outarray
End Function
Private Sub RetrieveError()
Err.Raise 5175, "Spider Class", "Function Error. " & _
"You cannot call any method or read " & _
"only property of the Spider Class " & _
"before calling the Retrieve Method."
End Sub
End Class
%>
See it Work