(ctx: str)
| 124 | |
| 125 | @staticmethod |
| 126 | def ctx2tree(ctx: str) -> html.HtmlElement: |
| 127 | # remove useless tags, eg. style and script |
| 128 | ctx = re.sub('<!--[\W\w]*?-->', '', ctx) |
| 129 | ctx = re.sub('<style[\W\w]*?>[\W\w]*?</style>', '', ctx) |
| 130 | ctx = re.sub('<script[\W\w]*?>[\W\w]*?</script>', '', ctx) |
| 131 | ctx = '' if ctx is None else re.sub(r'\s+', ' ', ctx).strip() |
| 132 | dom_tree = html.fromstring(ctx) |
| 133 | return dom_tree |
| 134 | |
| 135 | @staticmethod |
| 136 | def get_root(tree: html.HtmlElement) -> html.HtmlElement: |