AJAX asynchronously collects all videos and information from Youku albums (JavaScript code)

Source: Internet
Author: User

I am not satisfied with this because VB. NET in. in the. NET environment, network connections and regular expression matching consume a lot, and my final application is on video collection submission, therefore, we should consider using JavaScript AJAX + regular expressions to accomplish this goal.
I have never systematically studied JS and regular expressions in the past, so it takes longer than I expected. After a night, I am confused about the following code. =... = Copy codeThe Code is as follows: <! --
Night smell original, reprinted please keep this information, thank you very much!
Blog: http://clso.cnblogs.com
Home: http://cleclso.cn
QQ: 315514678 E-mail: clso # qq.com
Technical Exchange is welcome!
-->

<Html>
<Head>
<Title> javascipajax & Regular Expression test </title>
<Script type = "text/javascript" language = "javascript">
Function wrt (s ){
Subret. value = s + "\ n" + subret. value;
// Subret. value + = "\ n" + s;
}
Var objRequest; // defines an XML request object
Var previd = "", nowid = 0, listid = "", iscancel = false; // other variables
Function getlid (){
Var listid = weburl. value. match (/playlist_show \/.*(? = Id _ (\ d +). * \. html $/I );
If (! Listid ){
Return null;
} Else {
Return listid [1];
}
}
Function retweb (){
If (objRequest. readyState = 4 & objRequest. status = 200 ){
// Get callback
Var webstr = objRequest. responseText;
Vid = webstr. match (/var \ s + videoId \ s * = \ s * "(\ d +)" \ s *;/) [1];
Vtitle = webstr. match (/<title> (. +)-(. +)-video-youku video-watch online (-)? <\/Title>/) [2];
Wrt (nowid + ":" + vtitle + "=" + vid );
If (previd = vid) return;
Previd = vid;
Nowid + = 1;
// Start a new loop
If (iscancel) return;
Tstart ();
} Else {
// Alert ("Callback failed! ");
Return; // "error:" + objRequest. statusText;
}
}
Function getweb (u ){
ObjRequest = new XMLHttpRequest (); // new ActiveXObject ("Msxml2.XMLHTTP"); // IE5 & 6 initialize the XMLHTTP object
ObjRequest. onreadystatechange = retweb; // asynchronous callback Method
ObjRequest. open ("GET", u, true );
ObjRequest. send (null );
}
Function tstart (){
If (listid = ""){
Listid = getlid ();
}
Url = "http://v.youku.com/v_playlist/f" + listid + "o1p" + nowid + ". html ";
Getweb (url );
}

</Script>
</Head>
<Body>
<Input type = "text" id = "weburl" value = "http://www.youku.com/playlist_show/id_2350764.html" style = "width: 640"/> <br/>
<Textarea id = "subret" readonly = "readonly" style = "width: 640; height: 360;" ># star </textarea>
<Br/>
<Input type = button value = "Start album extraction" onclick = "if (iscancel) iscancel = false; tstart ();"/>
<Input type = button value = "clear text" onclick = "subret. value =''; nowid = 0; preid = ''; listid =''; "/>
<Input type = button value = "pause" onclick = "iscancel = true;"/>
</Body>
</Html>

The idea is basically the same as the previous one, so I will not repeat it.
The collection time of a page with VB. NET is generally about 1 second, and this Code relies on client scripts, each page is collected in 0.3 ~ About 0.5 seconds, depending on the user's computer configuration.
I personally passed the test with IE7, but the code is relatively casual, so the compatibility is not very good. If you need to use it, modify the code on your own.
Night smell original, reprinted please keep this information
Blog: http://clso.cnblogs.com/
Home: http://www.cleclso.cn/

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.