首先進入
http://m.fanfou.com 登錄好自己的帳號.
然后在chrome下按F12,切換到最后一欄"Console".
在里面粘貼下面代碼后回車:
var body = document.getElementsByTagName('body')[0];
var s = document.createElement('script');
s.setAttribute('type', 'text/javascript');
s.setAttribute('src', 'http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js');
body.appendChild(s);
然后再修改下面一段代碼,將要備份的那一項前面的 " // " 去掉
//收藏
//var next_url = "/favorites"; var type="fav";
//@我的
//var next_url = "/mentions"; var type="at";
//收到的私信
//var next_url = "/privatemsg"; var type="pri";
//發出的私信
//var next_url = "/privatemsg/sent"; var type="pri";
//個人消息
//var next_url = "/鏈接中的用戶名"; var type="usr";
var count = 0;
var src = [];
function save_log(){
if (typeof(next_url)!="undefined" && next_url!=null) {
$.get("http://m.fanfou.com" + next_url, function(data){
$("html").html(data);
if (type == "fav") {
var p1 = $("h2").next("p").next("p").next("p");
} else {
var p1 = $("h2").next("p");
}
while (p1.html() != null && p1.next("p").html() != null) {
src.push("<p>" + ++count + " " + p1.html() + "</p>\n");
console.log("<p>" + count + " " + p1.html() + "</p>\n");
p1 = p1.next("p");
}
next_url = p1.find("a:contains('下頁')").attr("href");
save_log();
});
} else {
var str = src.join("");
document.write(str);
console.log("備份完成.按ctrl+s保存本頁面.");
alert("備份完成.按ctrl+s保存本頁面.");
}
}
console.log("<link rel=\"stylesheet\" href=\"http://static.fanfou.com/css/m.css\" type=\"text/css\" media=\"screen\" charset=\"utf-8\">");
src.push("<style>body{font-family:Helvetica,Arial,sans-serif;word-break:break-all;word-wrap:break-word;text-overflow:ellipsis;}body,ul,ol,form{margin:0;padding:0;}ul,ol{list-style:none;}h1,h2,h3,div,li,p{margin:0;padding:2px 2px;font-size:medium;}h2,li,#nav,.b{border-bottom:1px solid #ccc;}h1{background:#0cf;}h2{background:#ccf5ff;}a{color:#06c;text-decoration:none;}a:hover,a:focus{background:#06c;color:#fff;}table a img{padding:2px;border:1px solid #ddd;background:#fff;}.p{font-weight:bold;}.search strong{font-weight:normal;color:red;}.n{border:1px solid #ffed00;background:#fffcaa;}.t,.a,#ft{color:#999;font-size:small;}#nav{border-top:1px solid #59a1b3;}.i{width:95%;padding:2px 0;margin:auto;}</style>");
save_log(); 將取消一句注釋的上面那段代碼也在"Console" 里面粘貼,然后回車.
然后就等結果吧.全部抓完之后會將結果顯示到網頁中. 按Ctrl+S就可以保存下來了.
這個腳本考慮了性能優化問題,但是不排除數據超多到了最后會卡的情況.請耐心等待吧..
歡迎各位在評論中就性能問題提供建議..
記錄一下優化的幾個點
一個是大字符串, 持續對String類型 += 造成性能問題.
后來改用數組, 挨個push字符串進去, 最后用join()組成大字符串, 效率高更多.
第二個是使用$("html").html(src)中參數為非常大的字符串時,
瀏覽器CPU占用100%并且頁面完全卡死無法恢復.
后來改用document.write(str), 重寫頁面速度大幅提升.
posted on 2012-08-22 04:50
ApolloDeng 閱讀(2434)
評論(1) 編輯 收藏 所屬分類:
分享 、
發布 、
Js/JQuery/Ajax 、
Web