千岁香包出庆阳:请网页高手帮助我一下,如何在自己的主页上加搜索,搜索站点内部的内容

来源:百度文库 编辑:杭州交通信息网 时间:2024/04/29 02:45:51

ASP站内搜索源码
<%
Option Explicit

Dim SearchString
Dim LenKey
Dim fs
Dim fd
'-----------
Const Catalog = "/" '被搜索的目录,请使用非绝对路径,当前使用默认的DOWNLOAD目录
Const Head = "PopSciChina.com" '搜索引擎标题
Const KeyStart = "<TITLE>" '被搜索的HTM结构文件的可搜索范围的头标记(大小写无所谓)
Const KeyEnd = "</TITLE>" '被搜索的HTM结构文件的可搜索范围的末标记(大小写无所谓)
Const FolderImg = "FOLDER.GIF" '代表目录的图片路径[可以不改]
Const FileImg = "FILE.GIF" '代表文件的图片路径[可以不改]
Const FileType = "htm" '文件类型,后缀名,此处默认的为搜索后缀名称为.ASP的文件内容
SearchString = Request("SearchString") '接收被搜索的数值[无需更改]
LenKey = Len(KeyStart) 'KeyStart字符长度[无需更改]

Function UnMapPath( Path )
UnMapPath = Replace(Mid(Path, Len(Server.MapPath("/")) + 1), "\", "/")
End Function

Function SearchFile( f, s, title )
Dim fo
Dim content
Dim pos1,pos2
On Error Resume Next
Set fo = fs.OpenTextFile(f)
content = fo.ReadAll
fo.Close
SearchFile = InStr(1, content, S, vbTextCompare) > 0
If SearchFile Then
pos1 = InStr(1, Lcase(content), Lcase(KeyStart), vbTextCompare)
pos2 = InStr(1, Lcase(content), Lcase(KeyEnd), vbTextCompare)
title = ""
If pos1 > 0 And pos2 > 0 Then
title = Mid( content, pos1 + LenKey, pos2 - pos1 - LenKey )
End If
End If
If Err Then
Response.Write ("<font color=red><B>")
Response.Write ("Error #" & CStr(Err.Number) & "" & Err.des cription )
Response.Write ("该文件名称为:" & f.Name & "<br>" & VbCrlf)
Response.Write ("</B></font>" & VbCrlf)
Else
Response.Write ("<font color=#000000>")
Response.Write ("Error #" & CStr(Err.Number) & "" & Err.des cription )
Response.Write ( f.name & "在正常运行<br>" & VbCrlf)
Response.Write ("</font>" & VbCrlf)
End If
End Function

Function FolderLink( fd )
Dim vPath
vPath = UnMapPath( fd.Path )
FolderLink = "<A HREF=""" & vPath & """>" & vPath & "</A>"
FolderLink = "<IMG SRC=" & FolderImg & " Align=TextTop> "& FolderLink
End Function

Function FileLink( f, title )
Dim vPath
vPath = UnMapPath( f.Path )
If title = "" Then title = f.Name
FileLink = "<A HREF=""" & vPath & """>" & title & "</A>"
FileLink = "<UL><IMG SRC=" & FileImg & " Align=TextTop> " & FileLink & "</UL>"
End Function

Sub SearchFolder( fd, s )
Dim found
Dim pos
Dim ext
Dim f
Dim sfd
Dim Title
found = False
For each f In fd.Files
pos = InStrRev(f.Path, "." )
If pos > 0 Then
ext = Mid(f.Path, pos + 1 )
Else
ext = ""
End If
If LCase(ext) = LCase(FileType) Then
If SearchFile( f, s, title ) Then
If found = False Then
found = True
Response.Write FolderLink(fd) & "<P>"
End If
Response.Write FileLink(f, title)
End If
End If
Next
For each sfd In fd.SubFolders
SearchFolder sfd, s
Next
End Sub
%>
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb_2312-80">
<title><%=Head%></title>
</head>

<body bgcolor="#FFFFFF">

<h2><%=Head%></h2>

<hr>

<form action="<%=Request.ServerVariables("s cript_NAME")%>" method="Get">
<p>请输入欲搜索的字串: <input type="text"
size="20" name="SearchString" value="<%=SearchString%>"> <input
type="submit" value="搜索"> </p>
</form>
<%
Set fs = Server.CreateObject("s cripting.FileSystemObject")
Set fd = fs.GetFolder( Server.MapPath(Catalog))

If SearchString <> "" Then
Response.Write "<H2>搜索 " & SearchString & " 的结果:</H2><P>"
SearchFolder fd, SearchString
End If
%>
<hr>
</body>
</html>