日韩天天综合网_野战两个奶头被亲到高潮_亚洲日韩欧美精品综合_av女人天堂污污污_视频一区**字幕无弹窗_国产亚洲欧美小视频_国内性爱精品在线免费视频_国产一级电影在线播放_日韩欧美内地福利_亚洲一二三不卡片区

解析網(wǎng)頁(yè)中添加新浪天氣預(yù)報(bào)的幾種方法_.Net教程

編輯Tag賺U幣
教程Tag:暫無Tag,歡迎添加,賺取U幣!

推薦:使用ASP.NET內(nèi)置類生成圖片縮略圖及水印
ASP.NETImageGeneration內(nèi)置了ImageResizeTransform類,可以實(shí)現(xiàn)圖片大小調(diào)整功能。也可以擴(kuò)展ImageTransform實(shí)現(xiàn)自己的圖片變換類。 下面使用ASP.NETImageGeneration生成圖片縮略圖及水印的代碼。 數(shù)據(jù)庫(kù): CREATETABLEt_images ( image_idINT, image_dataIM

    1.利用新浪提供給的iframe直接嵌入,這種方式非常的簡(jiǎn)單,但是卻沒有交互性。代碼如下:
<iframe frameborder="0" src="http://php.weather.sina.com.cn/widget/weather.php" scrolling="no" width="246" height="360"></iframe
    2.抓取當(dāng)天的天氣,以指定格式輸出。
涉及的核心代碼如下: 

public static ArrayList GetWeather(string code)
        {
            /*
            [0] "北京 "string
            [1] "雷陣雨 "string
            [2] "9℃" string
            [3] "29℃"string
            [4] "小于3級(jí)"string
            */
            string html = "";
            try
            {
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://weather.sina.com.cn/iframe/weather/" + code + "_w.html ");
                request.Method = "Get";
                //request.Timeout   =   1;
                request.ContentType = "application/x-www-form-urlencoded ";
                WebResponse response = request.GetResponse();
                Stream s = response.GetResponseStream();
                StreamReader sr = new StreamReader(s, System.Text.Encoding.GetEncoding("GB2312"));
                html = sr.ReadToEnd();
                s.Close();
                sr.Close();
            }
            catch (Exception err)
            {
                throw new Exception("訪問地址出錯(cuò)~~~ ");
            }

            int count = html.Length;
            int starIndex = html.IndexOf("<table ", 0, count);
            int endIndex = html.IndexOf("</table>", starIndex, count - starIndex);
            html = html.Substring(starIndex, endIndex - starIndex + 8);

            //得到城市
            int cityStartIndex = html.IndexOf("<b>", 0, html.Length);
            int cityEndIndex = html.IndexOf("</b>", 0, html.Length);
            string City = html.Substring(cityStartIndex + 3, cityEndIndex - cityStartIndex - 3);


            //得到天氣
            int weatherStartIndex = html.IndexOf("<b>", cityEndIndex);
            int weatherEndIndex = html.IndexOf("</b>", weatherStartIndex);
            string Weather = html.Substring(weatherStartIndex + 3, weatherEndIndex - weatherStartIndex - 3);

            //得到溫度

            int temperatureStartIndex = html.IndexOf("<b", weatherEndIndex);
            int temperatureEndIndex = html.IndexOf("</b>", weatherEndIndex + 3);
            string Temperature = html.Substring(temperatureStartIndex + 21, temperatureEndIndex - temperatureStartIndex - 21);

            int int1 = Temperature.IndexOf("℃", 0);
            int int2 = Temperature.IndexOf("~", 0);
            int int3 = Temperature.IndexOf("℃", int2);

            string MinTemperature = Temperature.Substring(int2 + 1, int3 - int2);
            string MaxTemperature = Temperature.Substring(0, int2 - int1 + 2);

            //得到風(fēng)力
            int windforceStartIndex = html.IndexOf("風(fēng)力:", temperatureEndIndex);
            int windforceEndIndex = html.IndexOf("<br>", windforceStartIndex);
            string Windforce = html.Substring(windforceStartIndex + 3, windforceEndIndex - windforceStartIndex - 3);

            if (Windforce.Contains("小于") && (!Windforce.Contains("等于")))                  //判斷風(fēng)力是否含有"小于"或"小于等于"字樣將,如果有的話,將其替換為2-
            {
                //Windforce = Windforce.Replace("小于", "2-");
                string strWindforce = Windforce.Substring(2, Windforce.Length - 3);
                int minWindforce = Int32.Parse(strWindforce) - 1;
                Windforce = Windforce.Replace("小于", minWindforce.ToString() + "-");

            }
            else if (Windforce.Contains("小于等于"))
            {
                string strWindforce = Windforce.Substring(4, Windforce.Length - 5);
                int minWindforce = Int32.Parse(strWindforce) - 1;
                Windforce = Windforce.Replace("小于等于", minWindforce.ToString() + "-");
            }

            ArrayList al = new ArrayList();
            al.Add(City);
            al.Add(Weather);
            al.Add(MinTemperature);
            al.Add(MaxTemperature);
            al.Add(Windforce);

            return al;
        }
這里涉及到一個(gè)ConvertCode類,它的作用是用于把城市轉(zhuǎn)換為對(duì)應(yīng)的全國(guó)統(tǒng)一的編碼,

分享:揭秘.Net開發(fā)常用十大輔助軟件
1.EditPlus:文字處理軟件 EditPlus是一款功能強(qiáng)大的文字處理軟件。它可以充分的替換記事本,它也提供網(wǎng)頁(yè)作家及程序設(shè)計(jì)師許多強(qiáng)悍的功能。支持HTML、CSS、PHP、ASP、Perl、C/C++、Java、JavaScript、VBScript等多種語法的著色顯示。程序內(nèi)嵌網(wǎng)頁(yè)瀏覽器,其

共2頁(yè)上一頁(yè)12下一頁(yè)
來源:模板無憂//所屬分類:.Net教程/更新時(shí)間:2010-04-13
相關(guān).Net教程