selectolax 0.3.21__cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl → 0.3.25__cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of selectolax might be problematic. Click here for more details.
- selectolax/__init__.py +1 -1
- selectolax/lexbor/node.pxi +51 -0
- selectolax/lexbor/util.pxi +19 -0
- selectolax/lexbor.c +37363 -17199
- selectolax/lexbor.cpython-311-aarch64-linux-gnu.so +0 -0
- selectolax/lexbor.pyi +21 -2
- selectolax/lexbor.pyx +1 -0
- selectolax/modest/node.pxi +40 -0
- selectolax/modest/util.pxi +19 -0
- selectolax/parser.c +33060 -14245
- selectolax/parser.cpython-311-aarch64-linux-gnu.so +0 -0
- selectolax/parser.pyi +21 -0
- selectolax/parser.pyx +1 -0
- selectolax/utils.pxi +94 -0
- {selectolax-0.3.21.dist-info → selectolax-0.3.25.dist-info}/METADATA +9 -3
- selectolax-0.3.25.dist-info/RECORD +26 -0
- {selectolax-0.3.21.dist-info → selectolax-0.3.25.dist-info}/WHEEL +1 -1
- selectolax-0.3.21.dist-info/RECORD +0 -24
- {selectolax-0.3.21.dist-info → selectolax-0.3.25.dist-info}/LICENSE +0 -0
- {selectolax-0.3.21.dist-info → selectolax-0.3.25.dist-info}/top_level.txt +0 -0
selectolax/__init__.py
CHANGED
selectolax/lexbor/node.pxi
CHANGED
|
@@ -655,6 +655,57 @@ cdef class LexborNode:
|
|
|
655
655
|
else:
|
|
656
656
|
raise SelectolaxError("Expected a string or LexborNode instance, but %s found" % type(value).__name__)
|
|
657
657
|
|
|
658
|
+
def insert_child(self, str_or_LexborNode value):
|
|
659
|
+
"""
|
|
660
|
+
Insert a node inside (at the end of) the current Node.
|
|
661
|
+
|
|
662
|
+
Parameters
|
|
663
|
+
----------
|
|
664
|
+
value : str, bytes or Node
|
|
665
|
+
The text or Node instance to insert inside the Node.
|
|
666
|
+
When a text string is passed, it's treated as text. All HTML tags will be escaped.
|
|
667
|
+
Convert and pass the ``Node`` object when you want to work with HTML.
|
|
668
|
+
Does not clone the ``Node`` object.
|
|
669
|
+
All future changes to the passed ``Node`` object will also be taken into account.
|
|
670
|
+
|
|
671
|
+
Examples
|
|
672
|
+
--------
|
|
673
|
+
|
|
674
|
+
>>> tree = LexborHTMLParser('<div>Get <img src=""></div>')
|
|
675
|
+
>>> div = tree.css_first('div')
|
|
676
|
+
>>> div.insert_child('Laptop')
|
|
677
|
+
>>> tree.body.child.html
|
|
678
|
+
'<div>Get <img src="">Laptop</div>'
|
|
679
|
+
|
|
680
|
+
>>> html_parser = LexborHTMLParser('<div>Get <span alt="Laptop"> <div>Laptop</div> </span></div>')
|
|
681
|
+
>>> html_parser2 = LexborHTMLParser('<div>Test</div>')
|
|
682
|
+
>>> span_node = html_parser.css_first('span')
|
|
683
|
+
>>> span_node.insert_child(html_parser2.body.child)
|
|
684
|
+
<div>Get <span alt="Laptop"> <div>Laptop</div> <div>Test</div> </span></div>'
|
|
685
|
+
"""
|
|
686
|
+
cdef lxb_dom_node_t * new_node
|
|
687
|
+
|
|
688
|
+
if isinstance(value, (str, bytes, unicode)):
|
|
689
|
+
bytes_val = to_bytes(value)
|
|
690
|
+
new_node = <lxb_dom_node_t *> lxb_dom_document_create_text_node(
|
|
691
|
+
&self.parser.document.dom_document,
|
|
692
|
+
<lxb_char_t *> bytes_val, len(bytes_val)
|
|
693
|
+
)
|
|
694
|
+
if new_node == NULL:
|
|
695
|
+
raise SelectolaxError("Can't create a new node")
|
|
696
|
+
lxb_dom_node_insert_child(self.node, new_node)
|
|
697
|
+
elif isinstance(value, LexborNode):
|
|
698
|
+
new_node = lxb_dom_document_import_node(
|
|
699
|
+
&self.parser.document.dom_document,
|
|
700
|
+
<lxb_dom_node_t *> value.node,
|
|
701
|
+
<bint> True
|
|
702
|
+
)
|
|
703
|
+
if new_node == NULL:
|
|
704
|
+
raise SelectolaxError("Can't create a new node")
|
|
705
|
+
lxb_dom_node_insert_child(self.node, <lxb_dom_node_t *> new_node)
|
|
706
|
+
else:
|
|
707
|
+
raise SelectolaxError("Expected a string or LexborNode instance, but %s found" % type(value).__name__)
|
|
708
|
+
|
|
658
709
|
@property
|
|
659
710
|
def raw_value(self):
|
|
660
711
|
"""Return the raw (unparsed, original) value of a node.
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
include "../utils.pxi"
|
|
2
|
+
|
|
3
|
+
def create_tag(tag: str):
|
|
4
|
+
"""
|
|
5
|
+
Given an HTML tag name, e.g. `"div"`, create a single empty node for that tag,
|
|
6
|
+
e.g. `"<div></div>"`.
|
|
7
|
+
"""
|
|
8
|
+
return do_create_tag(tag, LexborHTMLParser)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def parse_fragment(html: str):
|
|
12
|
+
"""
|
|
13
|
+
Given HTML, parse it into a list of Nodes, such that the nodes
|
|
14
|
+
correspond to the given HTML.
|
|
15
|
+
|
|
16
|
+
For contrast, HTMLParser adds `<html>`, `<head>`, and `<body>` tags
|
|
17
|
+
if they are missing. This function does not add these tags.
|
|
18
|
+
"""
|
|
19
|
+
return do_parse_fragment(html, LexborHTMLParser)
|