This article introduces how to use as3 to crawl web page source code and monitor the byte progress of reading.
The code has been tested by me and is available for reference only.
The code is as follows:
System.useCodePage=true; varvariables:URLVariables=newURLVariables(); variables.userName="Kakera"; variables.password="********"; varrequest:URLRequest=newURLRequest("http://www.baidu.com"); request.data=variables; request.method=URLRequestMethod.POST; varloader:URLLoader=newURLLoader(); loader.dataFormat=URLLoaderDataFormat.TEXT; loader.addEventListener(Event.COMPLETE,loader_complete); loader.addEventListener(Event.OPEN,loader_open); loader.addEventListener(HTTPStatusEvent.HTTP_STATUS,loader_httpStatus); loader.addEventListener(ProgressEvent.PROGRESS,loader_progress); loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR,loader_security); loader.addEventListener(IOErrorEvent.IO_ERROR,loader_ioError); loader.load(request); functionloader_complete(e:Event):void{ trace("Event.COMPLETE"); trace("目标文件的原始数据(纯文本):\n"+loader.data); } functionloader_open(e:Event):void{ trace("Event.OPEN");trace("读取了的字节:"+loader.bytesLoaded); } functionloader_httpStatus(e:HTTPStatusEvent):void{ trace("HTTPStatusEvent.HTTP_STATUS"); trace("HTTP状态代码:"+e.status); } functionloader_progress(e:ProgressEvent):void{ trace("ProgressEvent.PROGRESS"); trace("读取了的字节:"+loader.bytesLoaded); trace("文件总字节:"+loader.bytesTotal); } functionloader_security(e:SecurityErrorEvent):void{ trace("SecurityErrorEvent.SECURITY_ERROR"); } functionloader_ioError(e:IOErrorEvent):void{ trace("IOErrorEvent.IO_ERROR"); }
This article is provided by PHP Chinese website,
Article address: http://www.php.cn/java-article-377118 .html
To learn programming, come to PHP Chinese website www.php.cn
The above is the detailed content of AS3 Post method analysis of crawling pages and reading progress bars. For more information, please follow other related articles on the PHP Chinese website!