获取地区天气-基于yahoo

说明:
1. 城市名写死了,取的shenzhen,这个需要自己取;
2. 使用到Jsoup开源解析框架,这个自己去下载;
3. 第一步先获取城市的Code
	    public void initYahooWeatherData(){
	    	new Thread(new Runnable() {
				
				@Override
				public void run() {
			    	Document getCode;
					String getCityCode = "http://sugg.us.search.yahoo.net/gossip-gl-location/?appid=weather&output=xml&command="+"shenzhen";
					try {
						getCode = Jsoup.connect(getCityCode).get();
						Elements image = getCode.select("s");
						String mCityCode = null;
						for(Element el : image){
							String desiresStr = el.attr("d").toString();
							if(desiresStr.contains("woeid=")){
								desiresStr = desiresStr.substring(desiresStr.indexOf("woeid="),desiresStr.length());
								mCityCode = desiresStr.substring(desiresStr.indexOf("=")+1,desiresStr.indexOf("&"));
								break;
							}
						}
						Log.i("获取天气-城市Code", mCityCode+"---");
						if(!TextUtils.isEmpty(mCityCode)){
							Document mWeatherCode;
							String getWeatherCode = "http://weather.yahooapis.com/forecastrss?w="+mCityCode+"&u=c";
							try {
								mWeatherCode = Jsoup.connect(getWeatherCode).get();
								Log.i("获取天气", mWeatherCode+"---");
							} catch (IOException e) {
								// TODO: handle exception
							}
						}
					} catch (IOException e) {
						e.printStackTrace();
					}
				}
			}).start();;    		
	    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值