(node, tot_node, father_index, node_list, attrs)
| 46 | return c |
| 47 | |
| 48 | def build_dom_tree(node, tot_node, father_index, node_list, attrs): |
| 49 | node_index = tot_node |
| 50 | new_node = Dom_TreeNode(tot_node, father_index) |
| 51 | tot_node = tot_node + 1 |
| 52 | node_str = '' |
| 53 | if set(node.attrs.keys()) & set(attrs): |
| 54 | new_node.set_attr({x:y for x,y in node.attrs.items() if x in attrs}) |
| 55 | |
| 56 | for child in node.contents: |
| 57 | if isinstance(child, NavigableString): |
| 58 | if len(child.strip()) > 0: |
| 59 | text_node = Dom_TreeNode(tot_node, node_index) |
| 60 | tot_node = tot_node + 1 |
| 61 | text_node.set_tag('text') |
| 62 | text_node.set_str(child.strip()) |
| 63 | node_list.append(text_node) |
| 64 | new_node.append_children(tot_node - 1) |
| 65 | |
| 66 | elif isinstance(child, Tag) and child.name not in ['script', 'style']: |
| 67 | child_index, tot_node = build_dom_tree(child, tot_node, node_index, node_list, attrs) |
| 68 | if child_index == -1: |
| 69 | continue |
| 70 | new_node.append_children(child_index) |
| 71 | |
| 72 | new_node.set_tag(node.name) |
| 73 | |
| 74 | new_node.set_str(node_str) |
| 75 | node_list.append(new_node) |
| 76 | return new_node.get_index(), tot_node |
| 77 | |
| 78 | def build_tree(html, attrs=[]): |
| 79 | tot_node = 0 |
no test coverage detected