diff --git a/CHANGES.rst b/CHANGES.rst index 85bb62f..6294c9f 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,6 +1,15 @@ selectolax Changelog ==================== +Version 0.2.10 +-------------- + +Released + +- Fix root node property (`#32`_ ). The `root` property now points to the html tag. + +.. _#32: https://github.com/rushter/selectolax/issues/32 + Version 0.2.9 ------------- diff --git a/selectolax/node.pxi b/selectolax/node.pxi index 6766ca0..c539db6 100644 --- a/selectolax/node.pxi +++ b/selectolax/node.pxi @@ -546,7 +546,7 @@ cdef class Node: def unwrap_tags(self, list tags): """Unwraps specified tags from the HTML tree. - Works the same as th ``unwrap`` method, but applied to a list of tags. + Works the same as the ``unwrap`` method, but applied to a list of tags. Parameters ---------- diff --git a/selectolax/parser.pyx b/selectolax/parser.pyx index 077fd20..6891703 100644 --- a/selectolax/parser.pyx +++ b/selectolax/parser.pyx @@ -156,14 +156,10 @@ cdef class HTMLParser: @property def root(self): """Returns root node.""" - cdef myhtml_tree_node_t* root - root = myhtml_tree_get_document(self.html_tree) - - if root != NULL: + if self.html_tree and self.html_tree.node_html: node = Node() - node._init(root, self) + node._init(self.html_tree.node_html, self) return node - return None @property diff --git a/tests/test_nodes.py b/tests/test_nodes.py index a21ac57..ef92efe 100644 --- a/tests/test_nodes.py +++ b/tests/test_nodes.py @@ -286,7 +286,7 @@ def test_traverse(): ) html_parser = HTMLParser(html) actual = [node.tag for node in html_parser.root.traverse()] - expected = ['-undef', 'html', 'head', 'body', 'div', 'div', 'div', 'h1', 'div', 'img', 'div'] + expected = ['html', 'head', 'body', 'div', 'div', 'div', 'h1', 'div', 'img', 'div'] assert actual == expected @@ -297,7 +297,7 @@ def test_traverse_with_text(): ) html_parser = HTMLParser(html) actual = [node.tag for node in html_parser.root.traverse(include_text=True)] - expected = ['-undef', 'html', 'head', 'body', 'div', 'div', 'div', 'h1', '-text', 'div', '-text', 'img', 'div'] + expected = ['html', 'head', 'body', 'div', 'div', 'div', 'h1', '-text', 'div', '-text', 'img', 'div'] assert actual == expected diff --git a/tests/test_parser.py b/tests/test_parser.py index e4868e0..2261af3 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -49,3 +49,8 @@ def test_nodes(): html_output = htmlp.html assert len(html_output) >= len(html) assert SequenceMatcher(None, html, html_output).ratio() > 0.8 + + +def test_root_css(): + tree = HTMLParser('test') + assert len(tree.root.css('data')) == 0