中国代码恒熠百度小偷,演示地址http://baidu.china-code.net
以下为修正的web.aspx.cs
string str1,Result;
string wd=System.Web.HttpUtility.UrlEncode(Request.QueryString["wd"], System.Text.Encoding.GetEncoding("GB2312"));
string pn=Request.QueryString["pn"];
if (pn=="")
{
pn="0";
}
string PageUrl="http://www.baidu.com/s?wd="+wd+"&pn="+pn+"&lm=0&si=&rn=10&ie=gb2312&ct=0&cl=3&f=1";
WebClient wc = new WebClient();
wc.Credentials = CredentialCache.DefaultCredentials;
Byte[] pageData = wc.DownloadData(PageUrl);
Result = Encoding.Default.GetString(pageData);
string k = "抱歉,没有找到与“<font color=/"#C60A00/">" + wd + "</font>” 相关的网页";
if (Result.IndexOf(k)==-1)
{
string[] strtemp = System.Text.RegularExpressions.Regex.Split(Result, "<table border=/"0/" cellpadding=/"0/" cellspacing=/"0/" style=/"margin-left:18px;height:60px;/">");
Result = strtemp[0];
strtemp = null;
Result = System.Text.RegularExpressions.Regex.Replace(Result, @"提示:您可以在支持英汉互译的百度词典中查看(/S*)的解释", "");
Result = System.Text.RegularExpressions.Regex.Replace(Result, @"提示:(/S*)及其后面的字词均被忽略,因为百度的查询限制在38个汉字以内", "");
strtemp = System.Text.RegularExpressions.Regex.Split(Result, @"篇,用时");
str1 = strtemp[0];
Result = strtemp[1];
strtemp = null;
Result = System.Text.RegularExpressions.Regex.Replace(Result, @"找到相关网页约", "找到相关网页");
strtemp = System.Text.RegularExpressions.Regex.Split(str1, @"找到相关网页");
str1 = strtemp[1];
strtemp = null;
Response.Write("共有" + str1 + "条记录<br>");
//strtemp = System.Text.RegularExpressions.Regex.Split(Result, "<div style=/"background-color:#EFF2FA;height:60px;width:100%;clear:both/">");
//Result = strtemp[0];
// strtemp = null;
strtemp = System.Text.RegularExpressions.Regex.Split(Result, "DIV id=ScriptDiv>");
Result = strtemp[1];
strtemp = null;
Result = System.Text.RegularExpressions.Regex.Replace(Result, @"- <a href=(/S*) target=""_blank/"" class=m>百度快照</a>", "");
Result = System.Text.RegularExpressions.Regex.Replace(Result, @"a href=""s(/S*)""", "a href=$1");
Result = System.Text.RegularExpressions.Regex.Replace(Result, @"a href=s", "a href=");
Response.Write(Result);
}