CS代码:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net;
using System.IO;
using System.Text.RegularExpressions;public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ }
protected void Button1_Click(object sender, EventArgs e)
{
Uri u = new Uri("http://www.google.cn/search?q="+TextBox1.Text+"&hl=zh-CN&ie=GB2312&lr=&nxpt=10.2068337957705091425725");
HttpWebRequest dd = (HttpWebRequest)WebRequest.Create(u);
dd.Method = "GET";
WebResponse req = dd.GetResponse();
Stream str = req.GetResponseStream();
StreamReader readerOfStream = new StreamReader(str, System.Text.Encoding.GetEncoding("GB2312"));
string aa = readerOfStream.ReadToEnd();
string abc = "";
char aa1=(char)13;
char aa2=(char)10;
string Str = aa.Replace(aa1.ToString(), "").Replace(aa2.ToString(), "");
string StartStr = "<h3 class=r>[变量]";
StartStr = StartStr.Replace("[变量]", ".*");
string LastStr = "</h3>";
string SearchStr = StartStr + ".*" + LastStr;
Regex re = new Regex(SearchStr, RegexOptions.IgnoreCase);
Match m = re.Match(aa); Response.Write(m.Value);
str.Close();
}
}
html代码
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /></div>
</form>
</body>
</html>
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net;
using System.IO;
using System.Text.RegularExpressions;public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ }
protected void Button1_Click(object sender, EventArgs e)
{
Uri u = new Uri("http://www.google.cn/search?q="+TextBox1.Text+"&hl=zh-CN&ie=GB2312&lr=&nxpt=10.2068337957705091425725");
HttpWebRequest dd = (HttpWebRequest)WebRequest.Create(u);
dd.Method = "GET";
WebResponse req = dd.GetResponse();
Stream str = req.GetResponseStream();
StreamReader readerOfStream = new StreamReader(str, System.Text.Encoding.GetEncoding("GB2312"));
string aa = readerOfStream.ReadToEnd();
string abc = "";
char aa1=(char)13;
char aa2=(char)10;
string Str = aa.Replace(aa1.ToString(), "").Replace(aa2.ToString(), "");
string StartStr = "<h3 class=r>[变量]";
StartStr = StartStr.Replace("[变量]", ".*");
string LastStr = "</h3>";
string SearchStr = StartStr + ".*" + LastStr;
Regex re = new Regex(SearchStr, RegexOptions.IgnoreCase);
Match m = re.Match(aa); Response.Write(m.Value);
str.Close();
}
}
html代码
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /></div>
</form>
</body>
</html>
解决方案 »
- 发布网站后,ajax失效了!
- 关于在不同手机浏览器下获取手机UA信息的疑问,还请大牛帮忙指点!!!
- 如何读取Web.config MailSettings 在线等
- 遇到个很邪门的问题,按钮实效
- 数据库 未将对象引用设置到对象的实例问题
- TreeView控件,如果让每个节点在没有子节点的时候显示的图标不一样?
- iis升级到asp.net2.0后,以前用asp.net1.1的程序还能正常运行吗?
- 急急!!!关于asp.net中加载项目的问题
- .net给的GDI+作图是不是"粗糙"了点?
- 高手救命呀!asp.net生成Excel时的权限问题?
- 关于自动生成界面的问题
- 求助:求站内search功能源码
string param = "";
byte[] bs = Encoding.ASCII.GetBytes(param);
HttpWebRequest req = (HttpWebRequest) HttpWebRequest.Create("");
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
req.ContentLength = bs.Length;