您的位置:首页 > 编程语言 > C#

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;

            }

        }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  手机 google c# string url class
相关文章推荐