使用组件搜索

MicroSoft的ASP(Active Server Page)技术极大的方便了在网络中对于数据库的访问,而且由于ASP不同于CGI需要那么多的请求(减少了服务器的资源占用),以及ASP同Windows NT 、2000的结合使得ASP技术被广泛的应用于今日的Internet,然而不知道你仔细的想过没有!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!
代码开始:

1   
2'判断是输出页面还是处理数据,从而调用不同的部分   
3keyword=trim(request.form("keyword"))   
4if isnull(keyword) or keyword="" then   
 1<html>
 2<head>
 3<title>ASPCN.COM 超级搜索引擎</title>
 4<meta content="text/html; charset=utf-8" http-equiv="Content-Type"/>
 5<meta content="蒲俊杰" name="Author"/>
 6<meta content="ASP,组件,www.aspcn.com" name="Keywords"/>
 7<style type="text/css">   
 8<!--   
 9table { font-size: 9pt; font-style: normal}   
10.test { border: 1px #000000 dashed; border-color: #000000 none}   
11.test1 { background-color: #CCFFCC; clip: rect( ); font-size: 9pt; font-style:   
12normal; border-style: dashed; border-top-width: 1px; border-right-width: 1px; border-bottom-width:   
131px; border-left-width: 1px}   
14\-->   
15</style>
16</head>
17<body bgcolor="#FFFFFF" leftmargin="0" marginheight="0" marginwidth="0" topmargin="0">
18<table align="center" bgcolor="#66CC99" border="1" bordercolor="#FFFFFF" cellpadding="0" cellspacing="1" height="20" width="75%">
19<tr>
20<td height="4">
21<div align="center"><font color="#000000" face="Arial" size="2">ASPCN.COM</font><font color="#000000" face="Arial" size="3"></font><b><font color="#000000" face="Arial" size="3">
22</font><font color="#000000" face="仿宋_GB2312" size="3">超级搜索引擎</font></b></div>
23</td>
24</tr>
25<tr bordercolor="#66CC99">
26<td height="21">请选择下面的搜索引擎:(请注意:本搜索引擎只是适合于<font color="#ffffff">网页搜索   
27</font>)</td>
28</tr>
29<tr align="center" bordercolor="#FFFFFF" valign="top">
30<td height="20">
31<form action="http.asp" method="post">
32<table align="center" border="0" height="21" width="96%">
33<tr>
34<td height="10" width="31%">
35<div align="right">请输入你要搜索的关键字: </div>
36</td>
37<td height="10" width="69%">
38<input class="test" name="keyword" type="text"/>
39</td>
40</tr>
41<tr>
42<td height="2" width="31%">
43<div align="right">请选择你使用的搜索引擎: </div>
44</td>
45<td height="2" width="69%">
46<input name="yeah" type="checkbox" value="yeah"/>   
47Yeah   
48<input name="yahoo" type="checkbox" value="yahoo"/>   
49Yahoo   
50<input name="sina" type="checkbox" value="sina"/>   
51Sina   
52<input name="sohu" type="checkbox" value="sohu"/>   
53Sohu   
54<input name="goyoyo" type="checkbox" value="goyoyo"/>   
55Goyoyo</td>
56</tr>
57<tr>
58<td colspan="2" height="2">
59<div align="right">
60<input class="test1" name="Submit" type="submit" value="让我们开始吧"/>
61</div>
62</td>
63</tr>
64</table>
65</form>
66</td>
67</tr>
68<tr bordercolor="#FFFFFF">
69<td height="20">备注:由于使用了多个搜索引擎检索,所以系统输出的时间较长,请耐心等待... ...</td>
70</tr>
71<tr bordercolor="#FFFFFF">
72<td height="20">
73<div align="center">建议使用 IE 5.x 800*600访问 ASPCN.COM 版权保留(2000-2001) <font size="2">©</font></div>
74</td>
75</tr>
76</table>
77</body>
78</html>
 1else   
 2Server.ScriptTimeout = 100'设置脚本时间,由于系统输出时间较长所以必须修改脚本代码执行时间   
 3Set http = Server.CreateObject("AspHTTP.Conn")'连结组件   
 4keyword=request.form("keyword")'取得搜索关键字   
 5if request.form("yeah")="yeah" then'判断是否选择使用yeah搜索引擎   
 6http.Url = "http://search.163.com/cgi-bin/search/engine/search.fcgi?key="&keyword'处理搜索地址   
 7http.RequestMethod = "GET"'设置取得数据方式"GET,取得数据"   
 8response.write http.geturl'输出搜索结果   
 9end if   
10'以下代码请参考上例的说明,恕不罗嗦   
11'使用yahoo   
12if request.form("yahoo")="yahoo" then   
13http.Url = "http://google.yahoo.com/bin/query_gb?p="&keyword   
14http.RequestMethod = "GET"   
15response.write http.geturl   
16end if   
17'使用sohu   
18if request.form("sohu")="sohu" then   
19http.Url ="http://search.sohu.com/cgi-bin/search_main.cgi?   
20txt_keyword="&keyword&"&page_index=0&fuzzy=0&catagory=main"   
21http.RequestMethod = "GET"   
22response.write http.geturl   
23end if   
24'使用goyoyo   
25if request.form("goyoyo")="goyoyo" then   
26http.Url ="http://www.goyoyo.com.cn/gyy/query?dbs=guidedbs&code=GB&query="&keyword   
27http.RequestMethod = "GET"   
28response.write http.geturl   
29end if   
30set http=nothing   
31end if   
32'提交数据处理结束   
Published At
Categories with Web编程
Tagged with
comments powered by Disqus