ASP中使用组件搜索
来源:岁月联盟
时间:2006-02-28
< !--
有任何的意见和建议请Mail:pu.junjie@263.net,
本代码使用了http组件同时搜索出了几个搜索引擎的数据,让所有的搜索结果显示在一个页面当中,本文只是提供一种思路和思考
给大家展示ASP组件的强大功能!
由于本组件是非注册组件可能功能有一定限制,同时由于同时搜索了几个引擎(搜索引擎可以任意扩充,但是会影响速度的),所以系统输出数据的时间较长,请耐心等待
在使用本代码前请你先去下http://www.serverobjects.com/comp/asphttp3.zip,然好解压缩到你的system32目录(winnt or win2000)
使用regsvr32 asphttp.dll 注册本组件,然后拷贝本文件到相关的iis可执行目录,使用IE或者netscape浏览
-- >
< %
'判断是输出页面还是处理数据,从而调用不同的部分
keyword=trim(request.form("keyword"))
if isnull(keyword) or keyword="" then
% >
< !--
html页面代码显示
-- >
< html >
< head >
< title >ASPCN.COM 超级搜索引擎< /title >
< meta http-equiv="Content-Type" content="text/html; charset=gb2312" >
< META NAME="Author" CONTENT="蒲俊杰" >
< META NAME="Keywords" CONTENT="ASP,组件,www.aspcn.com" >
< style type="text/css" >
< !--
table { font-size: 9pt; font-style: normal}
.test { border: 1px #000000 dashed; border-color: #000000 none}
.test1 { background-color: #CCFFCC; clip: rect( ); font-size: 9pt; font-style: normal; border-style: dashed; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px}
-- >
< /style >
< /head > </P><P>< body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" >
< table width="75%" border="1" align="center" height="20" cellpadding="0" cellspacing="1" bgcolor="#66CC99" bordercolor="#FFFFFF" >
< tr >
< td height="4" >
< div align="center" >< font color="#000000" size="2" face="Arial" >ASPCN.COM< /font >< font color="#000000" size="3" face="Arial" >< /font >< b >< font color="#000000" size="3" face="Arial" >
< /font >< font color="#000000" size="3" face="仿宋_GB2312" >超级搜索引擎< /font >< /b >< /div >
< /td >
< /tr >
< tr bordercolor="#66CC99" >
< td height="21" >请选择下面的搜索引擎:(请注意:本搜索引擎只是适合于< font color="#ffffff" >网页搜索< /font >)< /td >
< /tr >
< tr bordercolor="#FFFFFF" align="center" valign="top" >
< td height="20" >
< form method="post" action="http.asp" >
< table width="96%" border="0" height="21" align="center" >
< tr >
< td height="10" width="31%" >
< div align="right" >请输入你要搜索的关键字: < /div >
< /td >
< td height="10" width="69%" >
< input type="text" name="keyword" class="test" >
< /td >
< /tr >
< tr >
< td height="2" width="31%" >
< div align="right" >请选择你使用的搜索引擎: < /div >
< /td >
< td height="2" width="69%" >
< input type="checkbox" name="yeah" value="yeah" >
Yeah
< input type="checkbox" name="yahoo" value="yahoo" >
Yahoo
< input type="checkbox" name="sina" value="sina" >
Sina
< input type="checkbox" name="sohu" value="sohu" >
Sohu
< input type="checkbox" name="goyoyo" value="goyoyo" >
Goyoyo< /td >
< /tr >
< tr >
< td height="2" colspan="2" >
< div align="right" >
< input type="submit" name="Submit" value="让我们开始吧" class="test1" >
< /div >
< /td >
< /tr >
< /table >
< /form >
< /td >
< /tr >
< tr bordercolor="#FFFFFF" >
< td height="20" >备注:由于使用了多个搜索引擎检索,所以系统输出的时间较长,请耐心等待... ...< /td >
< /tr >
< tr bordercolor="#FFFFFF" >
< td height="20" >
< div align="center" >建议使用 IE 5.x 800*600访问 ASPCN.COM 版权保留(2000-2001) < font size="2" >©< /font >< /div >
< /td >
< /tr >
< /table >
< /body >
< /html >
< !--
页面代码显示结束
数据处理代码显示
-- >
< %else
Server.ScriptTimeout = 100'设置脚本时间,由于系统输出时间较长所以必须修改脚本代码执行时间
Set http = Server.CreateObject("AspHTTP.Conn")'连结组件
keyword=request.form("keyword")'取得搜索关键字
if request.form("yeah")="yeah" then'判断是否选择使用yeah搜索引擎
http.Url = "http://search.163.com/cgi-bin/search/engine/search.fcgi?key=";&keyword'处理搜索地址
http.RequestMethod = "GET"'设置取得数据方式"GET,取得数据"
response.write http.geturl'输出搜索结果
end if
'以下代码请参考上例的说明,恕不罗嗦
'使用yahoo
if request.form("yahoo")="yahoo" then
http.Url = "http://google.yahoo.com/bin/query_gb?p=";&keyword
http.RequestMethod = "GET"
response.write http.geturl
end if
'使用sohu
if request.form("sohu")="sohu" then
http.Url ="http://search.sohu.com/cgi-bin/search_main.cgi?txt_keyword=";&keyword&"&page_index=0&fuzzy=0&catagory=main"
http.RequestMethod = "GET"
response.write http.geturl
end if
'使用goyoyo
if request.form("goyoyo")="goyoyo" then
http.Url ="http://www.goyoyo.com.cn/gyy/query?dbs=guidedbs&code=GB&query=";&keyword
http.RequestMethod = "GET"
response.write http.geturl
end if
set http=nothing
end if
'提交数据处理结束
% >
上一篇:asp下闰年计算方法
下一篇:在ASP中使用脚本语言