Repository navigation
Expand file tree
/
Copy pathparseXML.py
More file actions
118 lines (96 loc) · 3.81 KB
/
Copy pathparseXML.py
File metadata and controls
118 lines (96 loc) · 3.81 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
from xml.dom.minidom import parse,parseString
import sys
import chardet
class ParseXML():
def __init__(self):
self.root = ""
self.collection = ""
def parse(self,path):
domTree = parse(path)
self.collection = domTree.documentElement
self.root = domTree.getElementsByTagName("VIPSPage")[0]
def parseString(self,String):
try:
String = str(String.encode('utf-8'), encoding = "utf-8")
domTree = parseString(String)
except:
String = String.encode('utf-8').decode('gb2312','ignore')
domTree = parseString(String)
self.collection = domTree.documentElement
self.root = domTree.getElementsByTagName("VIPSPage")[0]
class VisualBlock():
def __init__(self):
self.type = ""
#layout Node attribute
self.BgColor = ""
self.ContainImg =""
self.ContainP =""
self.ContainTable =""
self.DOMCldNum = ""
self.DoC =""
self.FontSize=""
self.FontWeight=""
self.FrameSourceIndex=""
self.ID=""
self.IsImg = ""
self.LinkTextLen=""
self.order = ""
self.TextLen=""
#vipspage Node attribute
self.PageTitle = ""
self.Url = ""
self.WindowHeight = ""
self.WindowWidth = ""
#structure
self.x = ""
self.y = ""
self.width=""
self.height=""
self.childNodes = []
def toVisualBlock(self,node):
if node.nodeName == "LayoutNode":
self.type = "LayoutNode"
self.BgColor = node.getAttribute("BgColor")
self.ContainImg = node.getAttribute("ContainImg")
self.ContainP = node.getAttribute("ContainP")
self.ContainTable = node.getAttribute("ContainTable")
self.DOMCldNum = node.getAttribute("DOMCldNum")
self.DoC = node.getAttribute("DoC")
self.FontSize = node.getAttribute("FontSize")
self.FontWeight = node.getAttribute("FontWeight")
self.FrameSourceIndex = node.getAttribute("FrameSourceIndex")
self.ID = node.getAttribute("ID")
self.IsImg = node.getAttribute("IsImg")
self.LinkTextLen = node.getAttribute("LinkTextLen")
self.x = node.getAttribute("ObjectRectLeft")
self.y = node.getAttribute("ObjectRectTop")
self.width = node.getAttribute("ObjectRectWidth")
self.height = node.getAttribute("ObjectRectHeight")
self.TextLen = node.getAttribute("TextLen")
self.order = node.getAttribute("order")
if node.nodeName == "VIPSPage":
self.type = "VIPSPage"
self.height = node.getAttribute("PageRectHeight")
self.x = node.getAttribute("PageRectLeft")
self.y = node.getAttribute("PageRectTop")
self.width = node.getAttribute("PageRectWidth")
self.PageTitle = node.getAttribute("PageTitle")
self.Url = node.getAttribute("Url")
self.WindowHeight = node.getAttribute("WindowHeight")
self.WindowWidth = node.getAttribute("WindowWidth")
self.order = node.getAttribute("order")
#targetVisualBlockList.append(self)
if len(node.childNodes) > 0:
for node in node.childNodes:
if node.nodeName == "#text":
continue
vbc = VisualBlock()
vbc.toVisualBlock(node)
self.childNodes.append(vbc)
def allNode(self,list):
list.append(self)
if self.childNodes.__sizeof__() is not 0:
for child in self.childNodes:
child.allNode(list)
def __str__(self):
return ("order:%s x:%s y:%s width:%s height:%s" % (self.order, self.x, self.y, self.width, self.height))