2012-09-17 15 views
3

這可能是一種不可能的事情,但我想問一下。 有沒有辦法通過提供鏈接來獲取網頁的html源代碼?在as3中獲得網絡的源代碼

+1

你至少可以接受我的答案,如果它幫助你。或者讓我知道如果沒有。 – Gio

回答

9

當然有。我不明白你爲什麼得到如此多的反對票。總之,這裏的一個片段爲您:

var pageLoader:URLLoader = new URLLoader(); //make a loader that will load a page 
var pageRequest:URLRequest = new URLRequest("http://google.com"); //make a request with a url to page 
pageRequest.method = URLRequestMethod.GET; //set request's html request method to GET 

pageLoader.addEventListener(Event.COMPLETE, onPageLoaded); //listen for page load 
pageLoader.load(pageRequest); //actually load the page 

function onPageLoaded(e:Event):void 
{ 
    trace(pageLoader.data); //handle the data from the loader 
} 

您可以從您的處理函數使用e.target也得到你pageLoader實例的引用。祝你好運。