jnlp_crawler.py
· 920 B · Python
Originalformat
#!/usr/bin/env python
#
# jnlp_crawler.py - Download all the jar files in a jnlp file for offline examination
# Sheran Gunasekera
#
from xml.dom.minidom import parse
from xml.parsers.expat import ExpatError
import urllib
import sys
to_download = []
try:
dom = parse(sys.argv[1])
except ExpatError as (strerror):
print "!! JNLP File Parsing error -- "+str(strerror)
sys.exit(1)
jnlp = dom.getElementsByTagName("jnlp")
codebase = jnlp[0].getAttribute("codebase")
resources = dom.getElementsByTagName("resources")
for resource in resources:
jar = resource.getElementsByTagName("jar")
for attributes in jar:
to_download.append(attributes.getAttribute("href"))
for url in to_download:
try:
print "+ Attempt to fetch "+codebase+url
urllib.urlretrieve(codebase+url,url.split('/')[-1])
print "+ Done"
except IOError as (errno, strerror):
print "!! Failed -- "+strerror
except KeyboardInterrupt:
sys.exit(0)
| 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) |