-
Notifications
You must be signed in to change notification settings - Fork 13
/
fraunhofer_getdocs.py
46 lines (31 loc) · 939 Bytes
/
fraunhofer_getdocs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env python
"""
Script to take html of Fraunhofer site as an argument
and download all OOXML files.
"""
import re
import sys
import urllib2
html = sys.argv[1]
host = 'http:https://www.document-interoperability.com'
pattern = re.compile(r'/c/document_library/get_file.*?\"')
pattern2 = re.compile(r'images/document_library/.*?</a>')
f = open(html, 'rb')
htmlcontent = f.read()
f.close()
filenames = []
# get names
for result in pattern2.findall(htmlcontent):
filenames.append(result.split(' ', 1)[1].strip('</a>'))
filecount = 0
for result in pattern.findall(htmlcontent):
path = result.strip('"')
ext = re.search(r'name=.*?\..*', path).group()[-4:].strip('.')
filename = filenames[filecount]
file = urllib2.urlopen(host+path).read()
f = open((filename+'.'+ext), 'wb')
f.write(file)
f.close()
print filename + '.' + ext
filecount += 1
print 'Total: %d' % filecount