- @if (0)==(0) echo off
- setlocal enabledelayedexpansion
-
- echo,取得最新一期视频播放地址
- cscript -nologo -e:jscript %~s0 DownloadFile "http://cctv.cntv.cn/lm/huanqiucaijinglianxian/" "$"
- for /f "delims=" %%i in ('cscript -nologo -e:jscript %~s0 GetRegStr "$" "<a\shref='([^']+)'\starget='_blank'\stitle=''>[^<]+</a>"') do (
- echo,%%i&echo,&echo,
- set "strVideoUrl=%%i"
- goto :next
- )
-
- :next
- echo,传入视频播放地址,获取分析结果
- cscript -nologo -e:jscript %~s0 GetWebContent "!strVideoUrl!" "$"
- echo,&echo,
- set /a index=0
- set "today=%date:~0,10%"
- set "today=%today:/=%"
- set "today=%today:-=%"
- for /f "delims=" %%i in ('cscript -nologo -e:jscript %~s0 GetRegStr "$" "<BR><a\shref='([^']+)'[^>]+>[^<]+</a>"') do (
- set /a index+=1
- echo,!index! : %%i
- CScript -nologo -E:jscript %~s0 DownloadFile "%%i" "%cd%\%today%_!index!.mp4"
- echo,&echo,
- )
-
- :end
- del /f $
- pause & goto :EOF
-
- @end
-
- var fun = WScript.arguments(0);
- switch (fun){
- case "GetWebContent":
- if (WScript.arguments.length < 3) {
- WScript.echo("参数个数错误");
- WScript.quit();
- }
- var url = WScript.arguments(1);
- var fil = WScript.arguments(2);
- GetWebContent(GetEncodeURIComponentStr(url), fil);
- break;
-
- case "DownloadFile":
- if (WScript.arguments.length < 3) {
- WScript.echo("参数个数错误");
- WScript.quit();
- }
- var url = WScript.arguments(1);// + "?wshc_tag=1&wsts_tag=54b5d817&wsid_tag=abd9364e&wsiphost=ipdbm";
- var fil = WScript.arguments(2);
- GetWebContent(url, fil);
- break;
-
- case "GetEncodeURIComponentStr":
- if (WScript.arguments.length < 2) {
- WScript.echo("参数个数错误");
- WScript.quit();
- }
- var url = WScript.arguments(1);
- GetEncodeURIComponentStr(url);
- break;
-
- case "GetFileContent":
- if (WScript.arguments.length < 2) {
- WScript.echo("参数个数错误");
- WScript.quit();
- }
- var fil = WScript.arguments(1);
- GetFileContent(fil);
- break;
-
- case "GetRegStr":
- if (WScript.arguments.length < 3) {
- WScript.echo("参数个数错误");
- WScript.quit();
- }
- var fil = WScript.arguments(1);
- var regStr = WScript.arguments(2);
- regStr = regStr.replace(/'/g, "\"");
- GetRegStr(fil, regStr);
- break;
-
- default:;
- }
-
-
- function GetEncodeURIComponentStr(url){
- var encodeUrl = encodeURIComponent(url);
- var webUrl = "http://www.flvcd.com/parse.php?format=&kw="
- webUrl += encodeUrl;
- WScript.echo(webUrl);
- return webUrl;
- }
-
- function GetWebContent(url, fileName){
- try{
- var oHttp = new ActiveXObject("MSXML2.ServerXMLHTTP.4.0");
- oHttp.setProxy(1);
- oHttp.open("Get", url, false);
- WScript.echo("进入函数,传入参数为:" + url);
- oHttp.send("");
-
-
- if (oHttp.readyState == 4) {
- WScript.echo("内容获取完毕");
- //WScript.echo(oHttp.responseText);
- var oStream = new ActiveXObject("adodb.stream");
- oStream.Open();
- oStream.Type = 1;
- oStream.Write(oHttp.responseBody);
- oStream.Position = 0;
-
- var fso = new ActiveXObject("scripting.filesystemobject");
- if (fso.fileExists(fileName)) fso.deleteFile(fileName);
-
- oStream.SaveToFile(fileName);
- WScript.echo("写入文件:" + fileName);
- oStream.close();
- } else {
- WScript.echo("内容获取失败");
- }
-
- }catch (e){
- WScript.echo(e.message);
- }
- }
-
-
- function GetFileContent(fil){
- var oStream1 = new ActiveXObject("adodb.stream");
- oStream1.open();
- oStream1.charset = "GBK";
- oStream1.Type = 2;
- oStream1.LoadFromFile(fil);
-
- content = oStream1.ReadText();
- oStream1.Close();
-
- //WScript.echo(content);
- return content;
- }
-
-
- function GetRegStr(fil, regStr){
- //WScript.echo("正则表达式内容 : " + regStr);
- var reg = new RegExp(regStr, "g");
- var content = GetFileContent(fil);
- var ret = "";
-
- while ((collection = reg.exec(content)) != null) {
- //WScript.echo("正则匹配成功");
- ret += collection[1] + "\r\n";
- //WScript.echo(collection[1]);
- }
-
- WScript.echo(ret);
- return ret;
- }
复制代码
|