Download PDF from read.nlc.cn
This file contains 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 function downloadBook(aid, bid) { | |
const [title, myreader, kime, fime] = await getBookKey(aid, bid) | |
const r = await fetch(`http://read.nlc.cn/menhu/OutOpenBook/getReader?aid=${aid}&bid=${bid}&kime=${kime}&fime=${fime}`, { method: "POST", headers: { myreader: myreader }}) | |
const d = await r.arrayBuffer() | |
saveByteArray(title + ".pdf", d) | |
} | |
async function getBookKey(aid, bid) { | |
const r = await fetch(`http://read.nlc.cn/OutOpenBook/OpenObjectBook?aid=${aid}&bid=${bid}`) | |
const d = await r.text() | |
const title = /var title = \'(.+?)\'/.exec(d)[1] | |
const myreader = /tokenKey=\"(\w+)\"/.exec(d)[1] | |
const kime = /timeKey=\"(\w+)\"/.exec(d)[1] | |
const fime = /timeFlag=\"(\w+)\"/.exec(d)[1] | |
return [title, myreader, kime, fime] | |
} | |
// https://stackoverflow.com/a/37340749/5488616 | |
function saveByteArray(reportName, byte) { | |
var blob = new Blob([byte], {type: "application/pdf"}); | |
var link = document.createElement('a'); | |
link.href = window.URL.createObjectURL(blob); | |
var fileName = reportName; | |
link.download = fileName; | |
link.click(); | |
}; | |
downloadBook("403", "8179.0") | |
// To be executed at http://read.nlc.cn/ in the browser console |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment