24-7 網???????

Ynϥ WSH ӪAiHϥ Visual Basic 6 InetCtls.InetApGA|w˦AiH̷ӤUC覡ӶiwˡG
  1. qUC}UYɮ msinet.cabG
    http://activex.microsoft.com/controls/vb6/msinet.cab
    ]ݳƥG...\wsh\download\msinet.cab^
  2. msinet.cab iYAo MSINET.INF M MSINET.OCXANoɮש c:\windows\system32 ؿUC
  3. } DOS AiJ c:\windows\system32 ؿAuregsvr32 msinet.ocxvAYiwˡC
w˧Aڭ̴NiHϥ WSH ӪAШUCdҡG

lɡ]getWebPage01.js^G]ǦϰUYi^
// @Ӻ
inet=new ActiveXObject("InetCtls.Inet");		// o Inet Control 
inet.Url="http://www.cs.nthu.edu.tw";			// U
inet.RequestTimeOut=60;					// ]wծɶ
WScript.Echo("Downloading \""+inet.Url+"\"...");
content = inet.OpenURL();				// U
WScript.Echo(content);					// ܺe

ϥγqιB⦡Aڭ̥iHbAܦDAҦpG

lɡ]getWebPage02.js^G]ǦϰUYi^
// @ӺAçXD
inet=new ActiveXObject("InetCtls.Inet");		// o Inet Control 
inet.Url="http://www.cs.nthu.edu.tw";			// U
inet.RequestTimeOut=60;					// ]wծɶ
WScript.Echo("Downloading \""+inet.Url+"\"...");
content = inet.OpenURL();				// U
pattern = /<title>(.*)<\/title>/i;			// wqqΪܦ
title = pattern.exec(content);				// XD
WScript.Echo("u"+inet.Url+"vDOu"+RegExp.$1+"vI");	// ܵG

ڭ̤]iHb@ӺAߧYNxswФYɮסG

lɡ]getWebPage03.js^G]ǦϰUYi^
// @ӺAñN䤺esJ@ɮ
inet=new ActiveXObject("InetCtls.Inet");		// o Inet Control 
inet.Url="http://www.cs.nthu.edu.tw";			// U
inet.RequestTimeOut=20;					// ]wծɶ
WScript.Echo("Downloading \""+inet.Url+"\"...");
content = inet.OpenURL();				// U
// HUNegJɮ
fso = new ActiveXObject("Scripting.FileSystemObject");
forReading=1, forWriting=2;
fileName="test.htm";
fid=fso.OpenTextFile(fileName, forWriting, true);
fid.Write(content);
fid.Close();
WScript.Echo("qu"+inet.Url+"v쪺ewQsJu"+fileName+"vI");

ڭ̤]iHbAQγqΪܪkӧXs}Mr]Ancher Texts^G

lɡ]getWebPage04.js^G]ǦϰUYi^
// @ӺAéXeҦs]\äAiAiI^
inet=new ActiveXObject("InetCtls.Inet");		// o Inet Control 
inet.Url="http://www.cs.nthu.edu.tw";			// U
inet.RequestTimeOut=20;					// ]wծɶ
WScript.Echo("Downloading \""+inet.Url+"\"...");
content = inet.OpenURL();				// U
pattern=/<A(.*?)<\/A>/gi;				// wqqΪܦ
found=content.match(pattern);				// Xs
pattern2=/<\s*A\s+HREF\s*=\s*"?(.*?)"?\s*>(.*?)<\s*\/\s*A\s*>/i;	// t@ӳqιB⦡
for (i=0; i<found.length; i++){
	pattern2.exec(found[i]);		// Xs}Hγsr
	WScript.Echo(found[i]+" ===> URL="+RegExp.$1+", TEXT="+RegExp.$2);
}

bWzdҤAڭ̧Q WSH ӧMjTtAèϥγqΪܪkӧs}γsrA嫬XpUG

Downloading "http://www.cs.nthu.edu.tw"... <a href="2003NTHU_CS_Chinese.doc" target="_blank">()</a> ===> URL=2003NTHU_CS_Chinese.doc" target="_blank, TEXT=() <a href="2003NTHU_CS_English.doc" target="_blank">(^)</a> ===> URL=2003NTHU_CS_English.doc" target="_blank, TEXT=(^) <a href="/intro.html"><img src="/icon/csbuild_8.jpg" lowsrc="/icon/csbuild_7b.jpg" border=0 alt="MظT²v"></a> ===> URL=/intro.html, TEXT=<img src="/icon/csbuild_8.jpg" lowsrc="/icon/csbuild_7b.jpg" border=0 alt="MظT²v"> <a href="Grading_report.doc">tҦۧڵŲi</a> ===> URL=Grading_report.doc, TEXT=tҦۧڵŲi <a href="mailto:www@cs.nthu.edu.tw">N P </a> ===> URL=mailto:www@cs.nthu.edu.tw, TEXT=N P <a href="/webteam">s @ p </a> ===> URL=/webteam, TEXT=s @ p <a href="special.html"><font face="Arials"> N V & h</a> ===> URL=special.html, TEXT=<font face="Arials"> N V & h ... edҩҥΪ InetCtls.Inet A²AҥHLk_upAt@ IIS ت WinHttp.WinHttpRequestAhiHh\AHUdҥiH Google G

lɡ]getWebPage05.js^G]ǦϰUYi^
// @Ӻܨ䤺e
url="http://www.google.com";
try {
	WinHttpReq = new ActiveXObject("WinHttp.WinHttpRequest.5.1");
	WinHttpReq.Open("GET", url, false);
	WinHttpReq.Send();
	result = WinHttpReq.ResponseText;
} catch (objError) {
	result = objError+"\n";
	result += ("objError.number = "+(objError.number & 0xFFFF).toString()+"\n");
	result += ("objError.description = "+objError.description);
}
WScript.Echo(result);

Ū̥iHȰAAլݬݤWzdҡAN|LX줣~TFC

A]iHϥΥt@Ӥؤ XMLHTTP ӧG

lɡ]getUrl.js^G]ǦϰUYi^
url = "http://www.google.com.tw";
objHttp = new ActiveXObject("Microsoft.XMLHTTP");
objHttp.open("GET", url, false, "");
objHttp.send();
content = objHttp.responseText;
WScript.Echo(content);

ڭ̤]iHѦp jpg mid GiɮסG

lɡ]getBinaryFile.js^G]ǦϰUYi^
// Get Binary File from Web
// Usage: cscript getBinaryFile.js url output
// Example: cscript getBinaryFile.js http://neural.cs.nthu.edu.tw/jang/books/javascript/example/image/19980425/0041.jpg annie.jpg
// Roger Jang, 20081215, tested under Vista

args = WScript.Arguments;
if (args.Count()!=2) {
	WScript.Echo("Usage: cscript " + WScript.ScriptName + " url output");
	WScript.Echo("For example:");
	WScript.Echo("\tcscript " + WScript.ScriptName + " \"http://neural.cs.nthu.edu.tw/jang/books/javascript/example/image/19980425/0041.jpg\" \"annie.jpg\"");
	WScript.Quit();
}

url = args(0);
output = args(1);
getBinaryFile(url, output);

function getBinaryFile(url, output){

		// ====== ϥ Microsoft.XMLHTTP ɮסC
		http = WScript.CreateObject("Msxml2.ServerXMLHTTP.3.0");
		http.open("GET", url, false);
		WScript.Echo("Retrieving file at " + url);
		http.send();
		statusCode = http.status;
		if (statusCode != 200){			// ɮפ`
			WScript.Echo("Error in retrieving file at " + url);
			WScript.Echo("Status code = " + statusCode);
			WScript.Quit();
		}
		file = http.responseBody;
		BinaryStream = WScript.CreateObject("ADODB.Stream");
		BinaryStream.type = 1;
		BinaryStream.open();
		// ====== xsɮ
		WScript.Echo("Saving file to " + output + "...");
		BinaryStream.write(file);
		BinaryStream.saveToFile(output, 2);
		WScript.Echo("Done.");
}


JScript {]pPΡGΩ WSH