献上javascript抓取头像代码,非程序员 轻点
javascript:
var htmlURL = window.location.href;
var baselink = htmlURL.match(/.*=/g);
var toplink = "https://www.v2ex.com/recent?p=";
var toplinkNaN = "https://www.v2ex.com/recent?p=NaN";
if ( baselink != toplink || htmlURL==toplinkNaN )
{
window.open("https://www.v2ex.com/recent?p=1");
localStorage.setItem("message",'');
}
function getLastNumberStr(str)
{
var strs = str.replace(/.*=/g,'');
return strs;
}
var i = getLastNumberStr(htmlURL);
i++;
self.location=toplink+i.toString();
var singlereg= /(\/\/cdn\.v2ex\.co\/avatar).*(png)/g;
var html = document.documentElement.innerHTML;
var htmlele = html.match(singlereg).toString().replace(/normal/g,"large").replace(/\,/g," ").replace(/\/\//g,"https://").replace(/png/g,"png\n");
var localdata=localStorage.getItem("message");
htmlele += localdata;
localStorage.setItem("message",htmlele);
console.log(htmlele);
代码更新 最后面的数值是v2总页面数。本人非程序员,轻拍。:)
Array.prototype.uniquestr = function() {
var res = [];
var json = {};
for (var i = 0; i < this.length; i++) {
if (!json[this[i]]) {
res.push(this[i]);
json[this[i]] = 1;
}
}
return res;
}
var Urls = function(startUrl) {
this.startUrl = startUrl;
this.page = 0;
this.homePage = '';
this.heartsRecv = '';
}
Urls.prototype.crawl = function(titles) {
var self = this;
var url = self.startUrl + titles;
titles--;
var singlereg = /(\/\/cdn\.v2ex\.co\/avatar).*(png)/g;
$.get(url, function(data, status) {
self.homePage = data;
if (titles != undefined) {
self.heartsRecv += data;
}
setTimeout(function() {
if (titles > 0) {
self.crawl(titles);
} else {
self.heartsRecv = self.heartsRecv.match(singlereg).uniquestr().toString().replace(/normal/g, "large").replace(/\,/g, " ").replace(/\/\//g, "https://").replace(/png/g, "png\n");
console.log(self.heartsRecv);
return false;
}
}, 1000);
});
}
new Urls('https://www.v2ex.com/recent?p=').crawl(10000);
102
KanVivii 2017-01-04 09:22:01 +08:00 via iPhone
没有自己 伤心
|