Re: [問題] 請問要怎麼擷取網路時間

看板Flash作者 (CJ Cat)時間17年前 (2009/03/15 22:46), 編輯推噓4(407)
留言11則, 3人參與, 最新討論串2/2 (看更多)
回一篇來講如何抓這個網頁的時間 用的標準時間網頁是 http://www.timeanddate.com/worldclock/ 下面有一個框框裡面有 (我現在時間所看到的東西) Current UTC (or GMT/Zulu)-time used: Sunday, March 15, 2009 at 14:34:31 UTC is Coordinated Universal Time, GMT is Greenwich Mean Time. 那個14:34:31就是要抓的 GMT+0 時間 我的方法是用URLLoader載入網頁 var loader:URLLoader = new URLLoader(); loader.addEventListener(Event.COMPLETE, traceTime); loader.load(new URLRequest("http://www.timeanddate.com/worldclock/")); function traceTime(e:Event):void { var str:String = URLLoader(e.target).data; //抓所需文字的開頭,利用獨一無二的"ctu"這個字串來判斷 var startIndex:int = str.indexOf('<strong id="ctu">'); //接下來判斷之後第一次出現</strong>的位置 var endIndex:int = str.substr(startIndex).indexOf('</strong>'); //把指定範圍中間的字串用substring()取出來 //然後用split()把字串各區塊切開 var segments:Array = str.substring(startIndex, startIndex + endIndex).split(' '); //最後一個文區塊就是現在的時間 //在這裡用trace()把他印出來 trace(segments[segments.length - 1]); } -- CJ Cat = Croa'J Cat = Cockroach Cat = 西街凱特 = 蜚蠊貓 = 蟑螂貓 Blog http://cjcat.blogspot.com Gallery http://cjcat2266.deviantart.com ptt2 Board CJWorkshop - 阿多比閃光(Adobe Flash)研討區 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 61.228.90.42 ※ 編輯: cjcat2266 來自: 61.228.90.42 (03/15 22:47)

03/16 10:36, , 1F
請問'<strong id="ctu">'是什麼
03/16 10:36, 1F

03/16 14:32, , 2F
沒什麼,就是該網頁HTML裡面的標籤而已
03/16 14:32, 2F

03/16 14:32, , 3F
它會出現在時間資料的前面,所以我就拿它來當作判斷點
03/16 14:32, 3F

03/16 15:09, , 4F
請問是每個html網頁的時間前面都會有<strong id="ctu">嗎
03/16 15:09, 4F

03/16 15:11, , 5F
不然整個網頁如何判別你要讀取哪裡
03/16 15:11, 5F

03/16 15:14, , 6F
不會,cj其實有提到"該網頁"了 :)
03/16 15:14, 6F

03/16 15:15, , 7F
所以這個是得針對每個不同的網頁量身訂作的
03/16 15:15, 7F

03/16 15:28, , 8F
請問要怎麼知道該網頁在時間前面會出現<strong id="ctu">
03/16 15:28, 8F

03/16 15:29, , 9F
然後時間結束時會出現</strong>
03/16 15:29, 9F

03/16 17:15, , 10F
按右鍵→檢視原始碼
03/16 17:15, 10F

03/16 23:18, , 11F
瞭解了 謝謝樓上
03/16 23:18, 11F
文章代碼(AID): #19lHJBJS (Flash)
文章代碼(AID): #19lHJBJS (Flash)