Skip to content

Instantly share code, notes, and snippets.

@kasuganosora
Created August 3, 2013 23:22
Show Gist options
  • Save kasuganosora/6148364 to your computer and use it in GitHub Desktop.
Save kasuganosora/6148364 to your computer and use it in GitHub Desktop.
memoryforcer 获取字典
var $ = require('jquery').create();
var fs = require('fs');
var wordList = [];
var isEND =false;
function getDictContent(url,page,callback){
if(page == undefined){
page = 1;
}
var fullURL = url + "?page=" + page;
$.get(fullURL,function(data){
var dom = $(data);
console.log(fullURL);
var tbody = dom.find(".tab-content tbody:first tr");
var i,l;
for(i = 0, l = tbody.length; i < l; i++){
var tr = $(tbody[i]);
var tds = tr.find("td");
var td1 = tds.eq(0);
var td2 = tds.eq(1);
var description = td2.find("p:first").text();
var td1Text = td1.html().replace("<br />","\n");
var tTextArr = td1Text.split("\n");
var word = tTextArr[1];
var phonetic = tTextArr[0];
wordList.push({
word:word,
description:description,
phonetic:phonetic
});
}
isEND = dom.find(".next").hasClass("disabled");
}).done(function(){
console.log(">> PAGE:" +page+ " DONE <<< ");
if(isEND){
console.log("=== END ===");
callback(wordList);
}else{
page++;
setTimeout(function(){
getDictContent(url,page,callback);
},50);
}
});
}
getDictContent("http://www.memoryforcer.com/lists/510bc23236bf8ac76800ae38/words",1,function(){
var dict = {
content:wordList,
name:"GMAT核心词汇",
testMethod:"word"
};
fs.open(dict.name + ".json","w",0644,function(e,fd){
if(e) throw e;
fs.write(fd,JSON.stringify(dict),0,'utf8',function(e){
if(e) throw e;
fs.closeSync(fd);
})
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment