这是我在网上找的抓取谷歌,百度里面特定的搜索结果!但是有错误 忘哪位大虾帮忙指点一下..
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>
--------------------编程问答-------------------- 顶,我也菜鸟 只是怕他沉了 --------------------编程问答-------------------- --------------------编程问答-------------------- 晕,报什么错误,贴出了 --------------------编程问答-------------------- 是信息不对,还是程序出错? --------------------编程问答-------------------- 提示什么错误
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;
补充:.NET技术 , ASP.NET