Last active
March 20, 2023 19:28
-
-
Save MystK/ad649712769f7735e5b36b17499bf82a to your computer and use it in GitHub Desktop.
Download a Land Rover/Range Rover manual from Topix. Run on a page like: https://topix.jaguar.jlrext.com/topix/content/document/view?id=611070&groupId=1577 Downloads pdfs, assemble using Acrobat or similar.
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
links = []; | |
text = []; | |
function n(num) { | |
if (num > 99) return num; | |
if (num > 9) return `0${num}`; | |
return `00${num}`; | |
} | |
async function downloadURI(uri, name) { | |
await new Promise(res => setTimeout(() => res(), 100)); | |
var link = document.createElement("a"); | |
link.download = name; | |
link.href = uri; | |
link.dispatchEvent(new MouseEvent('click')); | |
} | |
var elements = document.querySelectorAll('.tree a') | |
for (let e of elements) { | |
h=e.href; | |
var split = h.split('/'); | |
var finalLink = `/topix/service/procedure/${split[4]}/ODYSSEY/${split[6]}/en_US/pdf?uid=${split[7].split('=')[1]}&layout=portrait`; | |
links.push(finalLink); | |
text.push(e.innerText); | |
}; | |
(async () => { | |
for (x = 0; x < links.length; x++) { | |
await downloadURI(links[x], `${n(x)} - ${text[x]}.pdf`); | |
} | |
})() |
Hi if you could help with some guidance it would be great, I get all the files as PDF's but they call just contain.
An unexpected error has occurred
error.message
Any help would be great.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi when I run the script from with the console in Chrome I get all the files downloaded but they are all just 1K file I can't open in a PDF reader. Did you manage to get this to download the files as PDF ?