获取google天气预报的ASP.NET代码

2009-2-11 10:53:48 作者:iuhxq 人气:
标签:天气预报(3)

获取google天气预报的ASP.NET代码

string city = string.Empty;

if (Request.QueryString["city"] != null && Regex.IsMatch(Request.QueryString["city"], "^[\u4e00-\u9fa5]+$", RegexOptions.Compiled))
{
city
= Request.QueryString["city"];
}
else
{
string ip = Request.UserHostAddress;
IPLocation iplocation
= IPLocationSearch.GetIPLocation(ip);
city
= iplocation.country;
}
if (city != string.Empty)
{
string url = string.Format("http://www.google.cn/search?hl=zh-CN&q=tq+{0}&meta=&aq=f&oq=", HttpUtility.UrlEncode(city, System.Text.Encoding.UTF8).ToUpper());
byte[] bytes = new System.Net.WebClient().DownloadData(url);
string html = System.Text.Encoding.Default.GetString(bytes);
int a = html.IndexOf("<div style=\"float:left\">");
if (a > 0)
{
a
+= 24;
int b = html.IndexOf("</td></tr></table></div>", a);
if (b > a)
{
Response.Write(html.Substring(a, b
- a).Replace("src=\"/", "src=\"http://www.google.cn/"));
return;
}
}
}
使用协议 - VIP服务 - 在线支付 - 联系我们 - 帮助文档 - Bug Report - 书签服务 - 联系电话:15079690152