- 周末没事,在重庆网通看连续剧,不过他没有提供一个很好的列表页面,一个列表页面没有提供翻页功能,只有700个电影列表,不能看到以前的连续剧。一个页面有翻页,但是每页只有10个影片,连续剧有200多个页面,要看以前的连续剧也要翻页很多次,在 [原创]Ajax基本原理讲解 里面的程序的基础上修改了一下,获取了所以连续剧的列表,方便观看。

大致原理如下:
- 用xmlhttp获取第一页源文件。
- 从源文件中提取影片的标题和地址,在页面中显示
- 获取下一页的源文件,提取标题和地址并显示。
- 重复,直到最后一页
源代码写得很乱,仅供参考。下载: cqcnc.zip


<HTML>
<HEAD>
<TITLE> 网通电影地址 </TITLE>
<META NAME="Author" CONTENT="http://pharaoh.cnblogs.com">
</HEAD>
<BODY>

<div id=load style="display:none; position:absolute;right:0px;top:0px;background:#FF5B5B;border:1px solid">正在加载
</div>


<input id=wurl style="500px" value="http://cncxp.cqwin.com/mov_list.asp?page={0}&class2id=9&Nclassid=&order=&updown=">
开始页:<input id=pagestart value='1'style="50px" />结束页:<input id=pageend value="216" style="50px" />
<button onclick="Begin();">加载</button>
<button onclick="stop();">停止</button>
<!--
<hr />
<div id=city>片断</div>
<hr />
<center><div id="wuhan_weather">数据区域</div></center>
<hr />
<div id=stext>代码区</div>
-->

<script language="javascript">
var loading = false;
var bgTime;
function Begin()

{
bgTime = new Date();
InsertHtml('<br />开始时间:'+bgTime);
loading = true;
GetWeather();
}
function stop()

{
loading = false;
}
var xmlhttp ;
function InsertHtml(html)

{
document.body.insertAdjacentHTML('beforeEnd',html);
}
function GetWeather()

{
if(!loading) return;
if(parseInt(document.getElementById('pagestart').value,10) > parseInt(document.getElementById('pageend').value,10))

{
var endTime = new Date();
InsertHtml('<br />结束时间:'+endTime+"<br />用时:"+(endTime - bgTime)/1000+"秒");
return;
}
window.status = '';
document.all("load").style.display='';
if(!xmlhttp)

{
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
xmlhttp.onreadystatechange = getReady;
}

xmlhttp.Open("GET",document.getElementById('wurl').value.replace('
{0}',document.getElementById('pagestart').value),true);
xmlhttp.Send();
}
function getReady()


{
window.status += xmlhttp.readyState+' ';
if(xmlhttp.readyState == 4)

{
document.all("load").style.display='none';
if(xmlhttp.status == 200)

{
var xmlReturn = bytes2BSTR(xmlhttp.ResponseBody); //xmlhttp.responseText;

//document.all("wuhan_weather").innerHTML=xmlReturn;
//document.all("stext").innerText=xmlReturn;
var newText = xmlReturn;//xmlReturn.replace(/\n+/g,' ');
//document.all("stext").innerText=newText;
var re = /<a class="date".+?a>/ig;
var cityText = newText.match(re);
var page = document.getElementById('pagestart').value;
var alink = '<hr /><a href="'+document.getElementById('wurl').value.replace('{0}',page)+'" target="_blank">第'+page+'页';
for(var i=0;i<cityText.length;i++)

{
alink +='<br />'+ cityText[i].replace('href="list.asp','target=_blank href="http://cncxp.cqwin.com/list.asp');
}
//document.all("city").innerHTML=cityText[2];
//document.all("city").innerHTML=alink;
InsertHtml(alink);
document.getElementById('pagestart').value = parseInt(document.getElementById('pagestart').value,10)+1;
xmlhttp = null;
GetWeather();
}
else

{
window.status = '出现错误:'+ xmlhttp.statusText+" "+xmlhttp.status;
xmlhttp = null;
window.setTimeout(GetWeather,10000);
}
//xmlhttp = null;
}

}

</script>

<script language="vbscript">
<!--
Function bytes2BSTR(vIn)
strReturn = ""
For i = 1 To LenB(vIn)
ThisCharCode = AscB(MidB(vIn,i,1))
If ThisCharCode < &H80 Then
strReturn = strReturn & Chr(ThisCharCode)
Else
NextCharCode = AscB(MidB(vIn,i+1,1))
strReturn = strReturn & Chr(CLng(ThisCharCode) * &H100 + CInt(NextCharCode))
i = i + 1
End If
Next
bytes2BSTR = strReturn
End Function
-->
</script>
</BODY>
</HTML>
