Skip to content

Instantly share code, notes, and snippets.

@MystK
Last active March 20, 2023 19:28
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MystK/ad649712769f7735e5b36b17499bf82a to your computer and use it in GitHub Desktop.
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.
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`);
}
})()
@pdedwards111
Copy link

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 ?

@pdedwards111
Copy link

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