Sheran Gunasekera a révisé ce gist 14 years ago. Aller à la révision
1 file changed, 33 insertions
jnlp_crawler.py(fichier créé)
| @@ -0,0 +1,33 @@ | |||
| 1 | + | #!/usr/bin/env python | |
| 2 | + | # | |
| 3 | + | # jnlp_crawler.py - Download all the jar files in a jnlp file for offline examination | |
| 4 | + | # Sheran Gunasekera | |
| 5 | + | # | |
| 6 | + | ||
| 7 | + | from xml.dom.minidom import parse | |
| 8 | + | from xml.parsers.expat import ExpatError | |
| 9 | + | import urllib | |
| 10 | + | import sys | |
| 11 | + | ||
| 12 | + | to_download = [] | |
| 13 | + | try: | |
| 14 | + | dom = parse(sys.argv[1]) | |
| 15 | + | except ExpatError as (strerror): | |
| 16 | + | print "!! JNLP File Parsing error -- "+str(strerror) | |
| 17 | + | sys.exit(1) | |
| 18 | + | jnlp = dom.getElementsByTagName("jnlp") | |
| 19 | + | codebase = jnlp[0].getAttribute("codebase") | |
| 20 | + | resources = dom.getElementsByTagName("resources") | |
| 21 | + | for resource in resources: | |
| 22 | + | jar = resource.getElementsByTagName("jar") | |
| 23 | + | for attributes in jar: | |
| 24 | + | to_download.append(attributes.getAttribute("href")) | |
| 25 | + | for url in to_download: | |
| 26 | + | try: | |
| 27 | + | print "+ Attempt to fetch "+codebase+url | |
| 28 | + | urllib.urlretrieve(codebase+url,url.split('/')[-1]) | |
| 29 | + | print "+ Done" | |
| 30 | + | except IOError as (errno, strerror): | |
| 31 | + | print "!! Failed -- "+strerror | |
| 32 | + | except KeyboardInterrupt: | |
| 33 | + | sys.exit(0) | |
Plus récent
Plus ancien