Last active
February 26, 2024 07:29
-
-
Save journey-ad/7a8596de20d67a69580087a218a5a4ca to your computer and use it in GitHub Desktop.
抓取P站收藏ID
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var ids = []; | |
function logcat(data, level){ | |
level = level.toUpperCase(); | |
if(level === 'I'){ | |
console.info('Info:', data); | |
}else if(level === 'W'){ | |
console.warn('Warning:', data); | |
}else if(level === 'E'){ | |
console.error('Error:', data); | |
}else{ | |
console.log(data); | |
} | |
} | |
function fetchIds(dom){ | |
resultWindow.document.body.style.wordWrap = 'break-word'; | |
if(!dom){ | |
resultWindow.document.title = '开始抓取'; | |
jQuery.get('https://www.pixiv.net/bookmark.php?rest=hide', function(data){ | |
logcat('正在抓取第 1 页', 'I'); | |
resultWindow.document.title = '正在抓取第 1 页'; | |
jQuery('form li.image-item img', data).each(function(index, img){ | |
ids.push(img.dataset.id); | |
resultWindow.document.body.innerHTML += (img.dataset.id+','); | |
}); | |
fetchIds(data); | |
}); | |
return | |
} | |
var next = jQuery('span.next a', dom)[0]?('https://www.pixiv.net/bookmark.php'+jQuery('span.next a', dom)[0].search):undefined; | |
console.log(next); | |
if(next){ | |
jQuery.get(next, function(data){ | |
logcat('正在抓取第 '+next.split('=')[2]+' 页', 'I'); | |
resultWindow.document.title = '正在抓取第 '+next.split('=')[2]+' 页'; | |
jQuery('form li.image-item img', data).each(function(index, img){ | |
ids.push(img.dataset.id); | |
resultWindow.document.body.innerHTML += (img.dataset.id+','); | |
}); | |
fetchIds(data); | |
}); | |
}else{ | |
ids = [...new Set(ids)]; | |
logcat('抓取完成,共 '+ids.length+' 个作品', 'I'); | |
console.log(ids.toString()); | |
resultWindow.document.title = '抓取完成,共 '+ids.length+' 个作品'; | |
resultWindow.document.body.innerHTML = ids.toString(); | |
resultWindow.focus(); | |
} | |
} | |
logcat('开始抓取', 'I'); | |
resultWindow = window.open('about:blank', '_blank', 'dialog=yes,width=600,height=300'); | |
fetchIds(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment