<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基礎
    主站蜘蛛池模板: 日韩人妻一区二区三区免费| 一进一出60分钟免费视频| 免费精品无码AV片在线观看| 亚洲综合精品香蕉久久网| WWW国产成人免费观看视频| 亚洲国产av无码精品| jizz免费观看| 亚洲精品国产精品乱码不99| 国产三级在线免费| 337p日本欧洲亚洲大胆艺术| 7723日本高清完整版免费| 亚洲ts人妖网站| 在线播放免费人成视频在线观看| 亚洲av色香蕉一区二区三区| 亚洲国产成人a精品不卡在线| 一级毛片试看60分钟免费播放| 久久久久久亚洲精品不卡| 中文在线免费不卡视频| 亚洲AV午夜福利精品一区二区| 99精品免费观看| 亚洲一线产品二线产品| 又粗又黄又猛又爽大片免费| 羞羞视频免费网站在线看| 亚洲国产精品不卡在线电影| 国产男女爽爽爽爽爽免费视频| 亚洲精品女同中文字幕| 亚洲乱码中文字幕手机在线| 久久精品无码精品免费专区| 亚洲一区二区三区久久| 亚洲午夜无码AV毛片久久| 最近免费中文字幕大全免费 | 免费a级毛片大学生免费观看| 高清免费久久午夜精品| 亚洲狠狠综合久久| 日本免费福利视频| 久草免费福利视频| 亚洲AV成人无码网站| 国产亚洲美女精品久久久久狼| 日本三级2019在线观看免费| 一级毛片人与动免费观看 | 亚洲AV综合永久无码精品天堂|