c# 调用Google查询天气 手机所属地 农历转换公历
2009-10-17 14:01
411 查看
红色字替换您需要的信息。
//获取最近三天天气情况
string url = string.Format("http://www.google.cn/search?hl=zh-CN&q=tq{0}&meta=&aq=f&oq=", HttpUtility.UrlEncode("上海
", 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 class=e>");
if (a > 0)
{
a += 13;
int b = html.IndexOf("<h2 class=hd>", a);
if (b > a)
{
Response.Write(html.Substring(a - 13, b - a + 13).Replace("src=/"/", "src=/"http://www.google.cn/"));
return;
}
}
//第一种:获取手机号所属地
string url = string.Format("http://www.google.cn/search?hl=zh-CN&q={0}&aq=f&oq=", "手机号
");
byte[] bytes = new System.Net.WebClient().DownloadData(url);
string html = System.Text.Encoding.Default.GetString(bytes);
int a = html.IndexOf("<div class=rbt>");
if (a > 0)
{
a += 15;
int b = html.IndexOf("<li class=g>", a);
if (b > a)
{
Response.Write(html.Substring(a - 15, b - a + 15).Replace("src=/"/", "src=/"http://www.google.cn/").Replace("href=/"/url", "href=/"http://www.google.cn/url"));
return;
}
}
/////////////////////////// 第二种:无标题页四川 南充 - 中国联通
string url = string.Format("http://www.google.cn/search?hl=zh-CN&q={0}&aq=f&oq=", "13281906391");
byte[] bytes = new System.Net.WebClient().DownloadData(url);
string html = System.Text.Encoding.Default.GetString(bytes);
int a = html.IndexOf("归属地查询</a></h3> ");
if (a > 0)
{
a += 20;
int b = html.IndexOf("<div style=/"margin:2px 0/">", a);
if (b > a)
{
Response.Write(html.Substring(a, b - a));
return;
}
}
//农历转换公历
string url = string.Format("http://www.google.cn/search?hl=zh-CN&q={0}&aq=f&oq=", HttpUtility.UrlEncode("n
l1981-6-5
", 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 class=e>");
if (a > 0)
{
a += 13;
int b = html.IndexOf("</table></table></div></div>", a);
if (b > a)
{
Response.Write(html.Substring(a - 13, b - a + 29).Replace("src=/"/", "src=/"http://www.google.cn/"));
return;
}
}
//通过sogou查询IP地址
string url = string.Format("http://www.sogou.com/web?query={0}&ast=&asf=&w=&num=&p=&dp=", "123.112.11.60");
byte[] bytes = new System.Net.WebClient().DownloadData(url);
string html = System.Text.Encoding.Default.GetString(bytes);
int a = html.IndexOf("<p class=/"ff/">");
if (a > 0)
{
a += 14;
int b = html.IndexOf("</p>", a);
if (b > a)
{
Response.Write(html.Substring(a - 14, b - a + 14));
return;
}
}
//获取最近三天天气情况
string url = string.Format("http://www.google.cn/search?hl=zh-CN&q=tq{0}&meta=&aq=f&oq=", HttpUtility.UrlEncode("上海
", 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 class=e>");
if (a > 0)
{
a += 13;
int b = html.IndexOf("<h2 class=hd>", a);
if (b > a)
{
Response.Write(html.Substring(a - 13, b - a + 13).Replace("src=/"/", "src=/"http://www.google.cn/"));
return;
}
}
//第一种:获取手机号所属地
string url = string.Format("http://www.google.cn/search?hl=zh-CN&q={0}&aq=f&oq=", "手机号
");
byte[] bytes = new System.Net.WebClient().DownloadData(url);
string html = System.Text.Encoding.Default.GetString(bytes);
int a = html.IndexOf("<div class=rbt>");
if (a > 0)
{
a += 15;
int b = html.IndexOf("<li class=g>", a);
if (b > a)
{
Response.Write(html.Substring(a - 15, b - a + 15).Replace("src=/"/", "src=/"http://www.google.cn/").Replace("href=/"/url", "href=/"http://www.google.cn/url"));
return;
}
}
/////////////////////////// 第二种:无标题页四川 南充 - 中国联通
string url = string.Format("http://www.google.cn/search?hl=zh-CN&q={0}&aq=f&oq=", "13281906391");
byte[] bytes = new System.Net.WebClient().DownloadData(url);
string html = System.Text.Encoding.Default.GetString(bytes);
int a = html.IndexOf("归属地查询</a></h3> ");
if (a > 0)
{
a += 20;
int b = html.IndexOf("<div style=/"margin:2px 0/">", a);
if (b > a)
{
Response.Write(html.Substring(a, b - a));
return;
}
}
//农历转换公历
string url = string.Format("http://www.google.cn/search?hl=zh-CN&q={0}&aq=f&oq=", HttpUtility.UrlEncode("n
l1981-6-5
", 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 class=e>");
if (a > 0)
{
a += 13;
int b = html.IndexOf("</table></table></div></div>", a);
if (b > a)
{
Response.Write(html.Substring(a - 13, b - a + 29).Replace("src=/"/", "src=/"http://www.google.cn/"));
return;
}
}
//通过sogou查询IP地址
string url = string.Format("http://www.sogou.com/web?query={0}&ast=&asf=&w=&num=&p=&dp=", "123.112.11.60");
byte[] bytes = new System.Net.WebClient().DownloadData(url);
string html = System.Text.Encoding.Default.GetString(bytes);
int a = html.IndexOf("<p class=/"ff/">");
if (a > 0)
{
a += 14;
int b = html.IndexOf("</p>", a);
if (b > a)
{
Response.Write(html.Substring(a - 14, b - a + 14));
return;
}
}
相关文章推荐
- Android手机集成天气预报功能方案:全国天气预报查询API调用
- 将公历转换成农历的类_C#
- 【C#】对异步请求处理程序IHttpAsyncHandler的理解和分享一个易用性封装 【手记】走近科学之为什么明明实现了IEnumerable<T>的类型却不能调用LINQ扩展方法 【手记】手机网页弹出层后屏蔽底层的滑动响应 【手记】ASP.NET提示“未能创建类型”处理 【Web】一个非常简单的移动web消息框 【手记】解决EXCEL跑SQL遇“查询无法运行或数据库表无法打开...”
- webService调用 查询手机号码和天气
- Java调用免费的WebService示例【天气预报】【国内手机号码归属地查询】
- 公历转换成农历的C#函数
- Python调用百度API之天气查询
- 调用第三方API ,实现手机号码归属地及运营商查询
- C#调用dll时的类型转换总结
- JavaScript实现公历转换农历
- C#调用C++的DLL搜集整理的所有数据类型转换方式
- C#调用GoogleEarth COM API开发(一)
- 调用天气api实现查询各城市天气
- 转载-公历转换农历VB示例
- 日历工具类(一)——公历农历互相转换
- C# 调用 Google Earth Com API开发(三)
- 用VS2008生成C++代码的dll及在C#中的调用及常见的类型转换
- C#调用VC的DLL的接口函数参数类型转换一览表
- C# (Winform) 颜色选择器的调用,以及RGB颜色与UInt颜色的转换
- 用VS2008生成C++代码的dll及在C#中的调用及常见的类型转换