理想很豐滿,現實很骨感,原本預想的是作一個完整的博客園閃存客戶端的,可是今天搞了一天,最終只弄成了這樣~~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~
來看看這沒整理的醜陋的不知道是否成功了沒的代碼......算了,仍是不讓看了~~