最近用asp.net做一个网站,需要做一个站内搜索的功能,我想直接用百度引擎,不知道怎么用,望做过的高手们给予指点,因为是初学asp.net,所以希望能够讲的详细点,最好能附上代码。不胜感激!
解决方案 »
- 上传图片显示0字节
- 页面含有treeview报theForm.elements.length为空或不是对象
- repeater数据绑定的问题
- RBAC权限问题!
- 自定义web控件,怎样才能保存System.Web.UI.Control类型得属性呢
- DataGrid1_ItemDataBound如何得到记录条数??
- 怎样实现DropDownList能编辑和自动匹配的功能(急啊!!!!!)
- java程序和。net的程序怎么连接在一起亚,session部能共享
- 怎么做上传附件这部分
- C#网络抓取
- 一个困惑的问题:指定aspx页的Codebehind属性到别的aspx.cs文件无效,马上给分
- 一条C#的语法
<%@ 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>
//获取要搜索的关键字,并定义类型
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();
}
有谁可不可以帮我改下我原有的代码。不胜感激!