-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathHTMLGraph.py
More file actions
36 lines (27 loc) · 780 Bytes
/
HTMLGraph.py
File metadata and controls
36 lines (27 loc) · 780 Bytes
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
from HTMLObject import HTMLObject
class HTMLNode:
"""HTMLNode from depth and object"""
def __init__(self, obj, depth, from_link = ""):
self.init_node = obj
self.curr_link = obj.link
self.graph = []
self.depth = depth
self.prev_link = from_link
def populate_graph(self):
for link in self.init_node.parsed_links():
obj = HTMLObject(link)
node = HTMLNode(obj, self.depth - 1, self.curr_link)
if node.depth > 0:
node.populate_graph()
self.graph.append(node)
def get_graph(self):
if self.graph == []:
self.populate_graph()
return self.graph
def print_node(self, precursor = ""):
print precursor + self.curr_link
for obj in self.graph:
obj.print_node(precursor + "\t")
def expand(self, dep):
depth = dep
self.populate_graph()