Last active
November 23, 2016 09:43
-
-
Save nym3r0s/32b04e75c58f4d2fc2a5 to your computer and use it in GitHub Desktop.
JS snippet to get all the links to files of any extension from a webpage
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
| var asdf = document.getElementsByTagName("a"); | |
| var asdfext = ".pdf"; | |
| for(var asdfinc =0 ; asdfinc < asdf.length;asdfinc++){ | |
| if(asdf[asdfinc].href.indexOf(asdfext)!=-1){ | |
| console.log(asdf[asdfinc].href); | |
| } | |
| } |
Author
Author
function downloadURI(uri, name) {
var link = document.createElement("a");
link.download = name;
link.href = uri;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
delete link;
}
var asdf = document.getElementsByTagName("a");
var asdfext = ".pdf";
for(var asdfinc =0 ; asdfinc < asdf.length;asdfinc++){
if(asdf[asdfinc].href.indexOf(asdfext)!=-1){
console.log(asdf[asdfinc].href);
var url = "" + asdf[asdfinc].href;
var filename = url.split('/').pop()
downloadURI(asdf[asdfinc].href,filename);
}
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
replace
asdfextwith any extension to generate the links in the console. Then use some utility like curl or wget to download it.