forked from buriy/python-readability
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug.py
More file actions
32 lines (28 loc) · 897 Bytes
/
Copy pathdebug.py
File metadata and controls
32 lines (28 loc) · 897 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
uids = {}
def save_to_file(text, filename):
f = open(filename, 'wt')
f.write("""
<meta http-equiv="Content-Type"
content="text/html; charset=UTF-8"
/>""")
f.write(text.encode('utf-8'))
f.close()
def describe(node, depth=2):
if not hasattr(node, 'tag'):
return "[%s]" % type(node)
name = node.tag
if node.get('id', ''):
name += '#' + node.get('id')
if node.get('class', ''):
name += '.' + node.get('class').replace(' ', '.')
if name[:4] in ['div#', 'div.']:
name = name[3:]
if name in ['tr', 'td', 'div', 'p']:
if not node in uids:
uid = uids[node] = len(uids) + 1
else:
uid = uids.get(node)
name += "%02d" % (uid)
if depth and node.getparent() is not None:
return name + ' - ' + describe(node.getparent(), depth - 1)
return name