理想很丰满,现实很骨感,原本预想的是作一个完整的博客园闪存客户端的,可是今天搞了一天,最终只弄成了这样~~html
下载地址:前端
windows 32位:http://pan.baidu.com/s/1gdqFs0Fnode
windows 64位:http://pan.baidu.com/s/1pJmvuivwindows
简单的罗列下吧:浏览器
1. 前端知识HTML+CSScookie
2. 依赖的nodejs库 网络
request : 网络请求dom
cheerio : 解析dom字符串post
3. NW.js 具体能够百度了解下ui
var handlerMap = { "all": analysisAll, "comment": analysisComment, "following": analysisFollowing, "my": analysisMy, "mycomment": analysisMyComment, "recentcomment": analysisRecentComment, "mention": analysisMention }; function analysis(ingListType, body) { return handlerMap[ingListType](body); } var analysisAll = function (body) { var result = []; $ = cheerio.load(body); $(".ing-item").each(function () { var item = {}; item.blogUrl = $(this).find(".feed_avatar").find("a").attr("href"); item.avatar = $(this).find(".feed_avatar").find("img").attr("src"); item.author = $(this).find(".feed_body").find(".ing-author").text(); item.body = $(this).find(".feed_body").find(".ing_body").text(); item.time = $(this).find(".feed_body").find(".ing_time").text(); item.detailUrl = $(this).find(".feed_body").find(".ing_time").attr("src"); item.ids = $(this).find(".feed_body").find(".ing_reply").attr("onclick"); item.comments = []; $(this).find(".feed_body").find(".ing_comments").find("li").each(function () { console.log($(this).text()); if ($(this).text().trim()) { var commentItem = {}; commentItem.time = $(this).find(".ing_comment_time").text(); commentItem.body = $(this).find(".ing_comment").text(); commentItem.author = $(this).find("[id*='comment_author']").text(); commentItem.ids = $(this).find(".ing_reply").attr("onclick"); item.comments.push(commentItem); } }); result.push(item); }); return result; }; module.exports.getIngList = function (ingListType, pageIndex, pageSize, callback) { var url = ingBaseUrl + "?" + "ingListType=" + ingListType + "&" + "pageIndex=" + pageIndex + "&" + "pageSize=" + pageSize; utils.get(url, function (body) { var result = analysis(ingListType, body); if (callback) { callback(result); } }); };
时间匆忙,最后也没写完,代码也没整理,写的很丑,只是让你们看看,不要借鉴,好比屡次使用$(this).find(".feed_avatar")而没有把它声明成变量。
上面代码的用途是从博客园获取闪存内容。
获取到的内容是html的,并不适合直接使用,因此,将html解析了一下,放到js对象中。
说下为何放弃了吧~~
上面显示全站的功能,写起来一直很顺畅,而后我就开始写其余模块。
其余模块都有涉及到登陆,而后就在浏览器F12里看博客园的代码。
登陆时候,用户名密码须要publickey来加密,还有须要一个VerificationToken,放在请求头里,publickey和这个token是一直变化的。
而后我就先请求到这个登陆页,拿到publickey和token还有cookie,而后把这些信息post过去,这样一直试,一直试,到最后居然让输入验证码了~~
好吧,give up~
来看看这没整理的丑陋的不知道是否成功了没的代码......算了,仍是不让看了~~