Last active
April 25, 2021 07:08
-
-
Save LewisGet/c7d45fe073afc5962b9f13c5583f13ea to your computer and use it in GitHub Desktop.
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
function get_content(dom) { | |
if (!dom.document) | |
return false; | |
if (!dom.document.getElementsByTagName("ul")) | |
return false; | |
return dom.document.getElementsByTagName("ul")[1].innerText; | |
} | |
function sleep(ms) { | |
return new Promise(resolve => setTimeout(resolve, ms)); | |
} | |
async function wait_selector(basic_dom, try_times) { | |
for (var i = 0; i < try_times; i++) { | |
var dom = get_content(basic_dom); | |
if (dom) | |
{ | |
console.log("not found"); | |
await sleep(1000); | |
continue; | |
} | |
return dom; | |
} | |
return false; | |
} | |
var contents = document.getElementsByTagName("ul")[1].innerText; | |
var next_page_url = document.querySelectorAll(".site-article-content > center > a")[1].getAttribute("href"); | |
var next_page = window.open(url); | |
for (var i = 0; i < 120; i++) { | |
await wait_selector(next_page, 30); | |
contents += get_content(next_page); | |
var next_page_url = next_page.document.querySelectorAll(".site-article-content > center > a")[1].getAttribute("href"); | |
if (next_page != false) | |
{ | |
next_page.window.close(); | |
} | |
var next_page = window.open(next_page_url); | |
await sleep(1000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment