(html, attrs=[])
| 76 | return new_node.get_index(), tot_node |
| 77 | |
| 78 | def build_tree(html, attrs=[]): |
| 79 | tot_node = 0 |
| 80 | node_list = [] |
| 81 | html = html.replace(' ',' ') |
| 82 | html = html.replace('<', '<') |
| 83 | html = html.replace('>', '>') |
| 84 | soup = BeautifulSoup(html, 'html.parser') |
| 85 | for element in soup(text=lambda text: isinstance(text, Comment)): |
| 86 | element.extract() |
| 87 | [s.extract() for s in soup('script')] |
| 88 | [s.extract() for s in soup('style')] |
| 89 | [s.extract() for s in soup('textarea')] |
| 90 | build_dom_tree(soup.html, tot_node, -1, node_list, attrs=attrs) |
| 91 | node_list = sorted(node_list, key=lambda x:x.get_index()) |
| 92 | return node_list |
| 93 | |
| 94 | def get_max_index(parse_tree, index): # get the max index of the subtree (must tag node not text node) |
| 95 | if len(parse_tree[index].get_children()) == 0: |
no test coverage detected