Last active
July 15, 2024 02:04
-
-
Save coo11/dbaaebd9dffaca0b803d0b7145483262 to your computer and use it in GitHub Desktop.
通过 Chrome 控制台,快速获取桃子圈( http://peachring.com/ )微博快照页码地址。
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
| (async () => { | |
| let n = 1000; //Page turning times | |
| let uid = "3139723905"; | |
| let cids = ["4208773252239704"]; | |
| let index = {}; | |
| /* http://m.peachring.com/weibo/user/3139723905/?next=${cid} | |
| * https://m.weibo.cn/${uid}/${cid} | |
| */ | |
| async function getHTML(id) { | |
| const res = await fetch( | |
| `http://m.peachring.com/weibo/user/${uid}/?next=${id}` | |
| ); | |
| if (res.status == 200) { | |
| return await res.text(); | |
| } | |
| } | |
| console.log(`Current page stay at ${cids[0] || 'start'}`) | |
| for (let i = 0; i < n; i++) { | |
| let cid = cids[i], | |
| text = await getHTML(cid); | |
| if (text) { | |
| let regex = /<(span|a).*?"time">\s*?(.*?)\s*?<\/\1>/g, | |
| stamps = [], | |
| matched, | |
| max = 0, | |
| min = Infinity; | |
| while ((matched = regex.exec(text))) { | |
| const stamp = new Date(matched[2]).getTime(); | |
| console.log(matched[2], stamp) | |
| stamps.push(stamp); | |
| max = Math.max(stamp, max); | |
| min = Math.min(stamp, min); | |
| } | |
| console.log(`Time stamps on this page are from ${min} to ${max}.`); | |
| index[cid] = { max: max, min: min }; | |
| let nextCid = text.match(/href="\?next=(\d*)"/); | |
| if (nextCid) { | |
| if (nextCid[1]) { | |
| cids[i + 1] = nextCid[1]; | |
| console.log(`Success. Turn to page ID ${nextCid[1]}.`); | |
| } else if (nextCid[1] === "") { | |
| console.log(`Page turning finished. ${i + 1} times executed.`); | |
| break; | |
| } | |
| } | |
| } | |
| } | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment