Flower in my dev/Python
<PYTHON>디렉토리 검색 및 xml 파싱 --> 파일 저장
꽃선생
2015. 5. 29. 09:54
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 |
import os, sys
from bs4 import BeautifulSoup
saveList = []
cnt01 = 0
cnt02 = 0
newPath = '경로/new_device'
oldPath = '경로/old_device'
nFile = 'flower_new'
oFile = 'flower_old'
nList = os.listdir(newPath)
oList = os.listdir(oldPath)
nFull = os.path.join(newPath, nFile)
oFull = os.path.join(oldPath, oFile)
for n in nList:
tmpPath = nFull + str(cnt01)
nWrite = open(tmpPath, 'w')
f = open(os.path.join(newPath, n))
xml = f.read()
fSoup = BeautifulSoup(xml, 'xml')
tmp = '[New Device Column]=====Sequence Number : ' + str(cnt01) + '\n'
nWrite.write(tmp)
for col in fSoup.findAll('measTypes'):
nWrite.write(col.string + '\n')
f.close()
nWrite.close()
cnt01 += 1
for o in oList:
tmpPath = oFull + str(cnt02)
oWrite = open(tmpPath, 'w')
f = open(os.path.join(oldPath, o))
xml = f.read()
fSoup = BeautifulSoup(xml, 'xml')
tmp = '[Old Device Column]=====Sequence Number : ' + str(cnt02) + '\n'
oWrite.write(tmp)
for col in fSoup.findAll('measTypes'):
oWrite.write(col.string + '\n')
f.close()
oWrite.close()
cnt02 += 1 |
cs |
디렉토리 두 곳에 존재하는 xml파일을 파싱하여
결과값을 파일에 저장하는 스크립트