修正一下- @set @i=0 /* & @echo off & cscript.exe -NoLogo -E:JScript %0 <单词列表.txt >结果.txt& pause & exit */
- var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
- function GetContent(url) {
- xmlhttp.open("GET", url ,false);
- xmlhttp.send();
- return(xmlhttp.responseText);
- }
- function getByClass(tag,Classname){
- if(html.getElementsByClassName){
- return html.getElementsByClassName(Classname);
- }
- var tags = html.getElementsByTagName(tag);
- for(var i = 0,len = tags.length; i < len; i++){
- if( tags[i].className ==Classname){
- return(tags[i]);
- }
- }
- }
- while (!WSH.StdIn.AtEndOfStream) {
- var s = WSH.StdIn.ReadLine();
- var str = s;
- var url = "http://dict.cn/" + str;
- var html = new ActiveXObject("htmlfile");
- html.write(GetContent(url));
- try {
- var ul = getByClass("div","basic clearfix");
- str += "\t" + ul.innerText.replace(/[\r\n]/gm,'') + "。\t";
- if (html.getElementById("dict-chart-basic")) {
- var obj = new Function("return" + unescape(html.getElementById("dict-chart-basic").data))();
- for(var key in obj ) { str += obj[key].percent > 5 ? obj[key].sense + ":"+ obj[key].percent + "%, " : ""};
- }
- var div = getByClass("div","layout sort");
- if (div) {
- str+= '\t'
- var b = div.getElementsByTagName("b");
- var ol = div.getElementsByTagName("ol");
- for (var i=0; i<ol.length; i++) {
- var s =b[i];
- if (s) { str+= s.innerText + '<br>' };
- var li= ol[i].getElementsByTagName("li");
- for (var j=0, len = li.length; j<len; j++) {
- if (j < 2) {str+= j+1 + '. ' + li[j].innerText + '<br>' };
- }
- }
- }
- }
- catch (e) {str += "\t" + "错误"};
- WSH.Echo(str.replace(/\r?\n/g,'<br>'));
- }
复制代码
|