flash AS2解析新浪网天气预报
点击次数:32 次 发布日期:2008-11-21 23:32:28 作者:源代码网
|
源代码网推荐
偶同事在用C#写,我就用AS2写,开始是抓QQ的,后来QQ发现啦,打乱了格式,不好抓了,呵呵~~把代码放上来,无非是一些字符串操作。
/**************************************************************************** * * 1---------------------------------------------------------l * | Wersling O o O O O O O O 00 | * l------------------------------------------------|--------l * S S * S S * /○ ● S S * /■/■ v * <| || | FLASH DESIGN ***************************************************************************** * @class com.wersling.weather.Weather * @author Wersling * @version 1.0 * @description 下载sina.com.cn天气预报 * @usage <pre>new Weather("http://weather.sina.com.cn/images/figureWeather/map/wholeNation.html");</pre> * ----------------------------------------------- * Latest update: 2005-08-02 * ----------------------------------------------- */ import com.wersling.utils.LoadText;
import com.wersling.events.EventDispatcher; import com.wersling.utils.Delegate; // class com.wersling.weather.Weather { private var _LoadText : LoadText; private var Str : String; // public var dispatchEvent : Function; public var addEventListener : Function; public var removeEventListener : Function; // //构造函数 // function Weather (path:String) { EventDispatcher.initialize (this); // _LoadText = new LoadText (); _LoadText.load (path); _LoadText.addEventListener ("complete", Delegate.create (this, onLoadcomplete)) } // //下载数据完成 // private function onLoadcomplete (Obj : Object) { var wertxt = unescape (Obj.Text); Str = new String (wertxt); Catch (); } // //处理数据 // private function Catch () { Str = intercept (Str, "name=Map>", "</MAP>"); var _arrWeatherList = Str.split ("<AREA"); for (var i in _arrWeatherList) { _arrWeatherList [i] = intercept (_arrWeatherList [i] , "城市", "<br> ");"); if (_arrWeatherList [i] == undefined) _arrWeatherList.splice(i,1); _arrWeatherList [i] = _arrWeatherList [i].split ("<br>"); for (var j in _arrWeatherList [i]) { _arrWeatherList [i][j] = _arrWeatherList [i][j].split (" ").join (""); //trace ("WeatherList[" + i + "][" + j + "]:" + _arrWeatherList [i][j]);
} } dispatchEvent ( { type : "complete", value : _arrWeatherList }); } // //截取字符 // private function intercept (Su : String, b : String, e : String) : String { var t = Su.indexOf (b); var s = Su.indexOf (e); if (Su.slice (t, s) != "") return Su.slice (t, s); } }
源代码网供稿. |