<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    隨筆-0  評論-3  文章-28  trackbacks-0
    名稱:根據IP地址顯示當前城市的天氣預報代碼1
    代碼:<iframe src="http://www.tianqi123.com/php/current_city.php" width=178 height=248 marginwidth=0 marginheight=0 hspace=0 vspace=0 frameborder=0 scrolling=no align=center id=url></iframe>
    效果
    說明:直接調用(原碼引用:http://www.tianqi123.com/)

    名稱
    根據IP地址顯示當前城市的天氣預報代碼2
    代碼:<iframe src="http://www.tianqi123.com/php/current_city.php?c0=F9DC68&c1=white&c2=FEFCE0&t1=red&bg=white&w=178&text=no" width=178 height=248 marginwidth=0 marginheight=0 hspace=0 vspace=0 frameborder=0 scrolling=no align=center id=url></iframe>
    效果
    說明:直接調用(原碼引用:http://www.tianqi123.com/)

    名稱:根據IP地址顯示當前城市的天氣預報代碼3
    代碼:<iframe src="http://www.tianqi123.com/php/current_city.php?c0=red&c1=D96C00&bg=F4FFF4&w=178&h=20&text=yes" width=178 height=21 marginwidth=0 marginheight=0 hspace=0 vspace=0 frameborder=0 scrolling=no align=center id=url></iframe>
    效果
    說明:直接調用(原碼引用:http://www.tianqi123.com/)

    天氣代碼高級使用方法:
     
    如果您會HTML語言,您還可以在iframe代碼中的url后面加參數,如:
    chengshi_321.html?c0=F9DC68&c1=white&c2=FEFCE0&t1=red&bg=white&w=178&h=250&text=no
     
    其中 c0 表示 表格第一行背景顏色,c1,c2表示表格其他行間隔的背景顏色,t1表示 標題顏色,bg 表示頁面北京顏色,w表示表格寬度 h 表示表格高度
     
    當 text=yes 時,將會出現滾動的天氣文字,建議您自己調試看看,如:
    chengshi_321.html??c0=red&c1=FF9900&bg=F4FFF4&w=178&h=20&text=yes
     
    注意:顏色請不要加 # 符號,如 #FF9900 請寫成 FF9900

    ------------------------------------------------------------------------------------------------------------------
    以下代碼(原碼引用:好多網站上都有)


    名稱:265天氣根據IP自動獲得當地的天氣情況
    代碼:<iframe src="http://weather.265.com/weather.htm" width="168" height="54" frameborder="no" border="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>
    效果

    說明:直接調用
    -----------------------------------------------------------------------------------

    名稱QQ天氣預報代碼(一)
    代碼:<iframe width="145" height="130" border="0" align="center" marginwidth="0" marginheight="0" hspace="0" vspace="0" frameborder="0" scrolling="no" src="http://minisite.qq.com/Weather/news_new.h tml" allowTransparency="true"></iframe>
    效果


    說明:這種適合于在網頁的邊欄插入。但一個缺點是,上面的4個城市是既定的,無法改成別的。插 入時,選好網頁上的位置,直接將左欄的源代碼全部拷進去就行了

    -------------------------------------------------------------------------------------------

    名稱QQ天氣預報代碼(二)
    代碼:<IFRAME ID='ifm2' WIDTH='189' HEIGHT='190' ALIGN='CENTER' MARGINWIDTH='0' MARGINHEIGHT='0' HSPACE='0' VSPACE='0' FRAMEBORDER='0' SCROLLING='NO' SRC='http://weather.qq.com/inc/ss258.htm'></IFRAME>
    效果


    說明:這種也適合于在網頁的邊欄插入。上面的城市可以自定,比如廈門可改成別的。定制的方法是修改我代碼中標紅的數字,從1開始代表“香港”開始,每個數字都代表一個城市,廈門是287,具體要哪個城市自己找一下罷。

    ----------------------------------------------------------------------------------------------------------

    名稱:新浪天氣預報代碼
    代碼:<IFRAME ID='ifm2' WIDTH='260' HEIGHT='70' ALIGN='CENTER' MARGINWIDTH='0' MARGINHEIGHT='0' HSPACE='0' VSPACE='0' FRAMEBORDER='0' SCROLLING='NO' src="http://news.sina.com.cn/iframe/weather/130101.html"></iframe>
    效果

    說明:這種適合于在網頁的頭欄插入。上面的城市可以自定,比如 石家莊可改成別的。

    ---------------------------------------------------------------------------------------------------------

    名稱:QQ天氣預報代碼(四)
    代碼:<iframe width=160 height=230 frameborder=0 scrolling=NO src=http://appnews.qq.com/cgi-bin/news_qq_search?city=南昌></iframe>
    效果


    說明:直接調用

    ------------------------------------------------------------------------------------------------------

    自己從網頁中偷取天氣數據
    主要用到Pattern類和Matcher類在java.util.regex.包下面。
    首先在網頁上取得所有數據
    HttpURLConnection conn = null;
            String outstr = "";
     try {
                String strUrl = "http://www.wopos.com/MainSet/WeatherSet.aspx?city="+address;
                URL url = new URL(strUrl);
                conn = (HttpURLConnection) url.openConnection();
                conn.setRequestMethod("GET");
                BufferedReader br = new BufferedReader(new InputStreamReader(conn.
                        getInputStream(), "GBK"));
                String line = "";
                while ((line = br.readLine()) != null) {
                    outstr = outstr + line;
                }
                br.close();
            } catch (Exception ex) {
                ex.printStackTrace(System.out);
            } finally {
                if (conn != null) {
                    conn.disconnect();
                }
            }
    然后分析數據
    try{
                Pattern p = Pattern.compile("<span id=\"Label\\d\" style=\"display:inline-block;\"><font size=\"\\d\">[\u4e00-\u9fa5]*\\d*[℃]*[~]*[.]*[-]*\\d*[℃]*[-]*\\d*[.]*\\d*[:]*[\u4e00-\u9fa5]*</font></span>");
                Matcher m = p.matcher(outstr);
                while (m.find()) {
                    String s = m.group();
    //                System.out.println("s=" + s);
                    if(s!=null){
                        hm.put(s.substring(10, 16), s);
                    }
                }
            }catch(Exception ex){
                ex.printStackTrace(System.out);
            }
    完整的例子為

    public class WoWeatherInit {

     Weather weather = new Weather();
     SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd");
     String time=df.format(date);
     public void getWeatherInit() {
            //開始分析返回的xml
            HttpURLConnection conn = null;
            String outstr = "";
            String outstrtest = "";
            ObjectInputStream input = null;
            HashMap hm = new HashMap();
            HashMap hm1 = new HashMap();
           
            try {
                String strUrl = "http://www.wopos.com/MainSet/WeatherSet.aspx?city="+address;
                URL url = new URL(strUrl);
                conn = (HttpURLConnection) url.openConnection();
                conn.setRequestMethod("GET");
                BufferedReader br = new BufferedReader(new InputStreamReader(conn.
                        getInputStream(), "GBK"));
                String line = "";
                while ((line = br.readLine()) != null) {
                    outstr = outstr + line;
                }
                br.close();
            } catch (Exception ex) {
                ex.printStackTrace(System.out);
            } finally {
                if (conn != null) {
                    conn.disconnect();
                }
            }
            if(outstr == null){
                System.out.println("null");
            }
            try{
                Pattern p = Pattern.compile("<span id=\"Label\\d\" style=\"display:inline-block;\"><font size=\"\\d\">[\u4e00-\u9fa5]*\\d*[℃]*[~]*[.]*[-]*\\d*[℃]*[-]*\\d*[.]*\\d*[:]*[\u4e00-\u9fa5]*</font></span>");
                Matcher m = p.matcher(outstr);
                while (m.find()) {
                    String s = m.group();
    //                System.out.println("s=" + s);
                    if(s!=null){
                        hm.put(s.substring(10, 16), s);
                    }
                }
            }catch(Exception ex){
                ex.printStackTrace(System.out);
            }

            String sAddress = getAddress(hm);
            String sDate = getDate(hm);
            String sTianQi = getTianQi(hm);
            String sWenDu = getWenDu(hm);
            String sWind = getWind(hm);
        }

        //獲取地址
        public String getAddress(HashMap hm){
         String sValue = "";
            try {
                String sText = (String)hm.get("Label5");
                String sFont = "<font size=\"2\">";
                int iBegin = sText.indexOf(sFont);
                int iEnd = sText.indexOf("</font>");
                sValue = sText.substring(iBegin+sFont.length(), iEnd);
            } catch (Exception ex) {
                ex.printStackTrace(System.out);
                sValue="";
            } finally{
             return sValue;
            }
        }

        //獲取天氣
        public String getTianQi(HashMap hm){
         String sValue = "";
            try {
                String sText = (String)hm.get("Label1");
                String sFont = "<font size=\"2\">";
                int iBegin = sText.indexOf(sFont);
                int iEnd = sText.indexOf("</font>");
                sValue = sText.substring(iBegin+sFont.length(), iEnd);
            } catch (Exception ex) {
                ex.printStackTrace(System.out);
                sValue="";
            } finally{
             return sValue;
            }
       }

    //  獲取日期
        public String getDate(HashMap hm){
         String sValue = "";
           try {
               String sText = (String)hm.get("Label7");
               String sFont = "<font size=\"2\">";
               int iBegin = sText.indexOf(sFont);
               int iEnd = sText.indexOf("</font>");
               sValue = sText.substring(iBegin+sFont.length(), iEnd);
           } catch (Exception ex) {
               ex.printStackTrace(System.out);
               sValue="";
           } finally{
            return sValue;
           }
       }
       
       //獲取溫度
       public String getWenDu(HashMap hm){
        String sValue = "";
           try {
               String sText = (String)hm.get("Label2");
               String sFont = "<font size=\"2\">";
               int iBegin = sText.indexOf(sFont);
               int iEnd = sText.indexOf("</font>");
               sValue = sText.substring(iBegin+sFont.length(), iEnd);
           } catch (Exception ex) {
               ex.printStackTrace(System.out);
               sValue="";
           } finally{
            return sValue;
           }
      }

    // 獲取風力
       public static String getWind(HashMap hm){
        String sValue = "";
           try {
               String sText = (String)hm.get("Label3");
               String sFont = "<font size=\"2\">";
               int iBegin = sText.indexOf("<font size=\"2\">");
               int iEnd = sText.indexOf("</font>");
               sValue = sText.substring(iBegin+sFont.length(), iEnd);
           } catch (Exception ex) {
               ex.printStackTrace(System.out);
           }
           return sValue;
       }
    }


    posted on 2008-01-24 09:37 閱讀(625) 評論(0)  編輯  收藏 所屬分類: java基礎
    主站蜘蛛池模板: 免费观看91视频| 免费无码又爽又刺激网站直播| 120秒男女动态视频免费| 亚洲国产AV无码专区亚洲AV| 中文字幕在线免费看线人| 亚洲午夜福利717| 成人久久免费网站| 亚洲精品综合一二三区在线 | 人妻仑刮八A级毛片免费看| 免费看国产一级片| 国产vA免费精品高清在线观看| 国产亚洲色视频在线| 国精产品一区一区三区免费视频| 亚洲成av人片天堂网| 国产在线jyzzjyzz免费麻豆 | 免费人成无码大片在线观看| 偷自拍亚洲视频在线观看99| 亚洲日韩国产成网在线观看 | 亚洲人成网站免费播放| 亚洲精品无码久久久久YW| 免费人成在线观看播放国产| 怡红院免费全部视频在线视频| 亚洲AV无码国产精品麻豆天美 | 久久精品国产亚洲AV无码娇色| 成年人视频免费在线观看| 亚洲色大网站WWW永久网站| 亚洲AV无码一区二区三区国产 | 亚洲一卡2卡三卡4卡有限公司| 亚洲欧洲免费无码| 一级毛片免费观看不收费| 亚洲区小说区图片区QVOD| 日本精品人妻无码免费大全| 免费又黄又爽又猛大片午夜| 亚洲成a人片在线观看无码| 91免费国产在线观看| 免费看黄网站在线看| 亚洲黄色免费网站| 全亚洲最新黄色特级网站 | 日韩av无码免费播放| 国产亚洲国产bv网站在线| 国产a v无码专区亚洲av|