|
还是先上图
理想很丰满,现实很骨感,本来预想的是做一个完整的博客园闪存客户端的,但是今天搞了一天,最终只弄成了这样~~
下载地址:
windows 32位:http://pan.baidu.com/s/1gdqFs0F
windows 64位:http://pan.baidu.com/s/1pJmvuiv
一、 主要用到的技术
简单的罗列下吧:
1. 前端知识HTML+CSS
2. 依赖的nodejs库
request : 网络请求
cheerio : 解析dom字符串
3. NW.js 具体可以百度了解下
二、 部分代码
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~
来看看这没整理的丑陋的不知道是否成功了没的代码......算了,还是不让看了~~ |
|
|