icrosoft的asp(active server page)技术极大的方便了在网络中对于数据库的访问,而且由于asp不同于cgi需要那么多的请求(减少了服务器的资源占用),以及asp同windows nt、2000的结合使得asp技术被广泛的应用于今日的inte.net, 然而不知道你仔细的想过没有!asp除了利用ado对数据库的访问和其他几个内置组件的利用外,就不能作其他什么的了,相对于perl,php等程序,asp的功能看起来就非常简单,而且功能缺乏;但是老比毕竟是老比,他给大家留了一手,那就是asp组件(关于组件的概念,现在一大堆,你可不要搞错了),通过组件的开发你可以做到其他语言(比如php,perl,c++)能做到的一切,甚至在某些方面还能更加超出,本文力求给你展示一下asp组件的强大功能,但是由于asp组件自身的过(使用的是非注册组件),可能有的时候使用会出现不稳定的状态,然而本文是力求向你展示一点东西以及提供一种思路给你,而不是其他,所以不足的地方就请求了原谅了!
代码思路:一般来看,我们提交一个表单给一个搜索引擎程序,搜索引擎获得提交的数据然后处理,返回结果;然而这种东西其实都是取得了一个提交的变量,我们可以使用另外一种直接跟从连接的方式访问搜索引擎,例如你可以使用yeah的首页搜索一个关键字“xuankong”,也可以使用下面的连接“http://search.163.com/cgi-bin/search/engine/search.fcgi?key=xuankong”取得使用结果,本文就是通过使用asp的http组件访问这种直接的连接,使用get方式取得原本在web页中返回的数据,然后输出。
如果本组件能够实现多线程(如果那样就可以同时对不同的引擎取得数据,不必象现在单一的访问然后取得结果,)和代码进一步的优化和改进的话,将会极大的节约你的时间,让你一次搜索同时返回多个引擎的结果!
备注:搜索出来的结果中,由于某些引擎的类目使用了相对的连接,所以无效(这些结果其实你都可以处理的,只是笔者太懒了,所以不想花那些功夫),但是所有的网站和网页的连接都是有效的,本文提供的代码只是适合于测试,不适合于具体的应用,如果需要具体的应用,需要使用适当的http组件,或者如果你是程序高手的话可以自己写多线程的组件,关于http组件的代码,你可以在www.chinaasp.com看到,欲得到更多的asp组件请访问www.aspcn.com!
代码开始:
<!--
有任何的意见和建议请mail:pu.junjie@263.net,
本代码使用了http组件同 阉鞒隽思父鏊阉饕娴氖荩盟械乃阉鹘峁允驹谝桓鲆趁娴敝校疚闹皇翘峁┮恢炙悸泛退伎几蠹艺故続sp组件的强大功能!
由于本组件是非注册组件可能功能有一定限制,同时由于同时搜索了几个引擎(搜索引擎可以任意扩充,但是会影响速度的),所以系统输出数据的时间较长,请耐心等待在使用本代码前请你先去下载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>
<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
’提交数据处理结束
%>
Java Asp PHP .Net XML C/C++ CGI VB Jsp J2ee J2se J2me EJB Servlet Tomcat Resin Struts Weblogic Eclipse ANT GUI JMS Web servise IDEA Webphere Hibernate Spring Jboss Applet Swing Socket Javamail Perl Ajax P2P 安全 模式 框架 测试 开源 游戏
Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器