最近用asp.net做一个网站,需要做一个站内搜索的功能,我想直接用百度引擎,不知道怎么用,望做过的高手们给予指点,因为是初学asp.net,所以希望能够讲的详细点,最好能附上代码。不胜感激!

解决方案 »

  1.   

    我写的search.aspx代码如下:(不过出现了两个问题,那就是输入关键字点“站内搜索"后会进入百度,关键字前面会加上站点site:(sbc.hust.edu.cn)但是后面的关键字却变成了乱码。最严重的是根本搜不到东西。)希望哪位高手帮忙解决一下,只有把这段代码考到.net环境下就可以运行着看了。本人现在比较急于解决这个问题,如能解决,马上给分。
    <%@ Page language="c#" Codebehind="search.aspx.cs" AutoEventWireup="false" Inherits="Ex02.WebForm1" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
    <HTML>
    <HEAD>
    <title>WebForm1</title>
    <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
    <meta name="CODE_LANGUAGE" Content="C#">
    <META http-equiv="Content-Type" content="text/html; charset=GB2312">
    <meta name="vs_defaultClientScript" content="JavaScript">
    <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
    <script>
    function go(formname)
    {
    var url = "http://www1.baidu.com/baidu";
    formname.method = "get";
    document.search_form1.word.value = "site:(sbc.hust.edu.cn)"+" "+document.search_form1.word.value;
    formname.action = url;
    return true;
    }
    </script>
    </HEAD>
    <body MS_POSITIONING="GridLayout">
    <center>
    <form onsubmit="return go(this)" target="_blank" name="search_form1" >
    <div align="center">
    <input name="tn" type="hidden" value="dabaoku"> <a href="http://www.baidu.com/"><img src="http://img.baidu.com/search/img/baidulogo_clarity_80_29.gif" alt="Baidu" align="bottom"
    border="0"></a> <input type="text" name="word" size="30"> <input type="submit" value="站内搜索">
    </div>
    </form>
    </center>
    </body>
    </HTML>
      

  2.   

    是不是可参考一下 .text blog 的源码,那个搜索我看做的不错,文件索引的,速度很快,但我没时间研究,你看看,明白了说明一下。
      

  3.   

    string  keyword =keyword.Text;
    //获取要搜索的关键字,并定义类型
    string searchkeyword= HttpUtility.UrlEncode(keyword,Encoding.GetEncoding("GB2312"));



    string web;web="http://www.baidu.com/s?wd="+searchkeyword666+"&cl=3";
    //抓取时会遇到抓取出来的文件缺少描绘样式,可以先把样式存入变量
    searchbody="<html><head><meta HTTP-EQUIV=content-type CONTENT=text/html; charset=UTF-8><style><!--<br>";
    searchbody=searchbody+"body,td,div,.p,a{font-family: }";
    searchbody=searchbody+                            " div{line-height:120%}";
    searchbody=searchbody+                           " div,td{color:#000}";
    searchbody=searchbody+                        " .f,.fl:link{color:#6f6f6f}";
    searchbody=searchbody+                  "a:link,.w,a.w:link,.w a:link{color:#00c}";
    searchbody=searchbody+                   "  a:visited,.fl:visited{color:#551a8b}";
    searchbody=searchbody+                         " a:active,.fl:active{color:#f00}";
    searchbody=searchbody+                  "  .t a:link,.t a:active,.t a:visited,.t{color:#000}";
    searchbody=searchbody+     "  .t{background-color:#e5ecf9}";
    searchbody=searchbody+   "  .k{background-color:#36c}";
    searchbody=searchbody+  " .j{width:34em}";
    searchbody=searchbody+               "  .h{color:#36c}";

    searchbody=searchbody+    " .i,.i:link{color:#a90a08}";
    //存取数据
    WebRequest req = WebRequest.Create(web);
             
    WebResponse result = req.GetResponse();
    Stream ReceiveStream = result.GetResponseStream();Byte[] read = new Byte[512];
    int bytes = ReceiveStream.Read(read, 0, 512);     
           
    while (bytes > 0)
    {
    Encoding encode = System.Text.Encoding.GetEncoding("gb2312");
    bytes = ReceiveStream.Read(read, 0, 512);
    searchbody=searchbody+encode.GetString(read,0,bytes);
    }DateTime dt=DateTime.Now;

    Random rd=new Random();
    //创建本地搜索结果文件,并将抓取数据写入该文件
    resultfilename=searchkeyword+dt.Year.ToString()+dt.Month.ToString()+dt.Day.ToString()+dt.Hour.ToString()+dt.Minute.ToString()+dt.Second.ToString()+rd.Next(0,10000)+".htm";
    StreamWriter sr = File.CreateText(Server.MapPath("web/"+webname+"/"+resultfilename));
    sr.Close();
    using (StreamWriter sw = new StreamWriter(Server.MapPath("web/"+webname+"/"+resultfilename))){
    sw.Write(searchbody);
    sw.Close();
    }
      

  4.   

    上面的代码是用什么语言写的,怎么那么麻烦?我用的是asp.net(c#)
    有谁可不可以帮我改下我原有的代码。不胜感激!
      

  5.   

    我要用百度引擎。因为我这边上google要用代理。