selectolax 0.3.30__cp312-cp312-win_amd64.whl → 0.3.32__cp312-cp312-win_amd64.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/lexbor.pyi CHANGED
@@ -1,8 +1,10 @@
1
- from typing import Any, Iterator, Literal, TypeVar, NoReturn, overload
1
+ from typing import Any, Iterator, Literal, TypeVar, NoReturn, overload, Optional
2
2
 
3
3
  DefaultT = TypeVar("DefaultT")
4
4
 
5
5
  class LexborAttributes:
6
+ """A dict-like object that represents attributes."""
7
+
6
8
  @staticmethod
7
9
  def create(node: LexborAttributes) -> LexborAttributes: ...
8
10
  def keys(self) -> Iterator[str]: ...
@@ -11,7 +13,7 @@ class LexborAttributes:
11
13
  def __iter__(self) -> Iterator[str]: ...
12
14
  def __len__(self) -> int: ...
13
15
  def __getitem__(self, key: str) -> str | None: ...
14
- def __setitem__(self, key: str, value: str) -> None: ...
16
+ def __setitem__(self, key: str, value: Optional[str]) -> None: ...
15
17
  def __delitem__(self, key: str) -> None: ...
16
18
  def __contains__(self, key: str) -> bool: ...
17
19
  def __repr__(self) -> str: ...
@@ -25,24 +27,49 @@ class LexborAttributes:
25
27
  def sget(self, key: str, default: str = "") -> str: ...
26
28
 
27
29
  class LexborSelector:
30
+ """An advanced CSS selector that supports additional operations.
31
+
32
+ Think of it as a toolkit that mimics some of the features of XPath.
33
+
34
+ Please note, this is an experimental feature that can change in the future.
35
+ """
36
+
28
37
  def __init__(self, node: LexborNode, query: str): ...
29
38
  def css(self, query: str) -> NoReturn: ...
30
39
  @property
31
- def matches(self) -> list[LexborNode]: ...
40
+ def matches(self) -> list[LexborNode]:
41
+ """Returns all possible matches"""
42
+ ...
32
43
  @property
33
- def any_matches(self) -> bool: ...
44
+ def any_matches(self) -> bool:
45
+ """Returns True if there are any matches"""
46
+ ...
34
47
  def text_contains(
35
48
  self, text: str, deep: bool = True, separator: str = "", strip: bool = False
36
- ) -> LexborSelector: ...
49
+ ) -> LexborSelector:
50
+ """Filter all current matches given text."""
51
+ ...
37
52
  def any_text_contains(
38
53
  self, text: str, deep: bool = True, separator: str = "", strip: bool = False
39
- ) -> bool: ...
54
+ ) -> bool:
55
+ """Returns True if any node in the current search scope contains specified text"""
56
+ ...
40
57
  def attribute_longer_than(
41
58
  self, attribute: str, length: int, start: str | None = None
42
- ) -> LexborSelector: ...
59
+ ) -> LexborSelector:
60
+ """Filter all current matches by attribute length.
61
+
62
+ Similar to string-length in XPath.
63
+ """
64
+ ...
43
65
  def any_attribute_longer_than(
44
66
  self, attribute: str, length: int, start: str | None = None
45
- ) -> bool: ...
67
+ ) -> bool:
68
+ """Returns True any href attribute longer than a specified length.
69
+
70
+ Similar to string-length in XPath.
71
+ """
72
+ ...
46
73
 
47
74
  class LexborCSSSelector:
48
75
  def __init__(self): ...
@@ -50,109 +77,732 @@ class LexborCSSSelector:
50
77
  def any_matches(self, query: str, node: LexborNode) -> bool: ...
51
78
 
52
79
  class LexborNode:
80
+ """A class that represents HTML node (element)."""
81
+
53
82
  parser: LexborHTMLParser
54
83
  @property
55
84
  def mem_id(self) -> int: ...
56
85
  @property
57
- def child(self) -> LexborNode | None: ...
86
+ def child(self) -> LexborNode | None:
87
+ """Alias for the first_child property."""
88
+ ...
58
89
  @property
59
- def first_child(self) -> LexborNode | None: ...
90
+ def first_child(self) -> LexborNode | None:
91
+ """Return the first child node."""
92
+ ...
60
93
  @property
61
- def parent(self) -> LexborNode | None: ...
94
+ def parent(self) -> LexborNode | None:
95
+ """Return the parent node."""
96
+ ...
62
97
  @property
63
- def next(self) -> LexborNode | None: ...
98
+ def next(self) -> LexborNode | None:
99
+ """Return next node."""
100
+ ...
64
101
  @property
65
- def prev(self) -> LexborNode | None: ...
102
+ def prev(self) -> LexborNode | None:
103
+ """Return previous node."""
104
+ ...
66
105
  @property
67
- def last_child(self) -> LexborNode | None: ...
106
+ def last_child(self) -> LexborNode | None:
107
+ """Return last child node."""
108
+ ...
68
109
  @property
69
- def html(self) -> str | None: ...
110
+ def html(self) -> str | None:
111
+ """Return HTML representation of the current node including all its child nodes.
112
+
113
+ Returns
114
+ -------
115
+ text : str
116
+ """
117
+ ...
70
118
  def __hash__(self) -> int: ...
71
- def text_lexbor(self) -> str: ...
72
- def text(
73
- self, deep: bool = True, separator: str = "", strip: bool = False
74
- ) -> str: ...
75
- def css(self, query: str) -> list[LexborNode]: ...
119
+ def text_lexbor(self) -> str:
120
+ """Returns the text of the node including text of all its child nodes.
121
+
122
+ Uses builtin method from lexbor.
123
+ """
124
+ ...
125
+ def text(self, deep: bool = True, separator: str = "", strip: bool = False) -> str:
126
+ """Returns the text of the node including text of all its child nodes.
127
+
128
+ Parameters
129
+ ----------
130
+ strip : bool, default False
131
+ If true, calls ``str.strip()`` on each text part to remove extra white spaces.
132
+ separator : str, default ''
133
+ The separator to use when joining text from different nodes.
134
+ deep : bool, default True
135
+ If True, includes text from all child nodes.
136
+
137
+ Returns
138
+ -------
139
+ text : str
140
+ """
141
+ ...
142
+ def css(self, query: str) -> list[LexborNode]:
143
+ """Evaluate CSS selector against current node and its child nodes.
144
+
145
+ Matches pattern `query` against HTML tree.
146
+ `CSS selectors reference <https://www.w3schools.com/cssref/css_selectors.asp>`_.
147
+
148
+ Parameters
149
+ ----------
150
+ query : str
151
+ CSS selector (e.g. "div > :nth-child(2n+1):not(:has(a))").
152
+
153
+ Returns
154
+ -------
155
+ selector : list of `Node` objects
156
+ """
157
+ ...
76
158
  @overload
77
159
  def css_first(
78
160
  self, query: str, default: Any = ..., strict: Literal[True] = ...
79
- ) -> LexborNode: ...
161
+ ) -> LexborNode:
162
+ """Same as `css` but returns only the first match.
163
+
164
+ Parameters
165
+ ----------
166
+
167
+ query : str
168
+ default : bool, default None
169
+ Default value to return if there is no match.
170
+ strict: bool, default True
171
+ Set to True if you want to check if there is strictly only one match in the document.
172
+
173
+
174
+ Returns
175
+ -------
176
+ selector : `LexborNode` object
177
+ """
178
+ ...
80
179
  @overload
81
180
  def css_first(
82
181
  self, query: str, default: DefaultT, strict: bool = False
83
- ) -> LexborNode | DefaultT: ...
182
+ ) -> LexborNode | DefaultT:
183
+ """Same as `css` but returns only the first match.
184
+
185
+ Parameters
186
+ ----------
187
+
188
+ query : str
189
+ default : bool, default None
190
+ Default value to return if there is no match.
191
+ strict: bool, default True
192
+ Set to True if you want to check if there is strictly only one match in the document.
193
+
194
+
195
+ Returns
196
+ -------
197
+ selector : `LexborNode` object
198
+ """
199
+ ...
84
200
  @overload
85
201
  def css_first(
86
202
  self, query: str, default: None = ..., strict: bool = False
87
- ) -> LexborNode | None: ...
88
- def any_css_matches(self, selectors: tuple[str]) -> bool: ...
89
- def css_matches(self, selector: str) -> bool: ...
203
+ ) -> LexborNode | None:
204
+ """Same as `css` but returns only the first match.
205
+
206
+ Parameters
207
+ ----------
208
+
209
+ query : str
210
+ default : bool, default None
211
+ Default value to return if there is no match.
212
+ strict: bool, default True
213
+ Set to True if you want to check if there is strictly only one match in the document.
214
+
215
+
216
+ Returns
217
+ -------
218
+ selector : `LexborNode` object
219
+ """
220
+ ...
221
+ def any_css_matches(self, selectors: tuple[str]) -> bool:
222
+ """Returns True if any of CSS selectors matches a node"""
223
+ ...
224
+ def css_matches(self, selector: str) -> bool:
225
+ """Returns True if CSS selector matches a node."""
226
+ ...
90
227
  @property
91
228
  def tag_id(self) -> int: ...
92
229
  @property
93
- def tag(self) -> str | None: ...
94
- def decompose(self, recursive: bool = True) -> None: ...
95
- def strip_tags(self, tags: list[str], recursive: bool = False) -> None: ...
230
+ def tag(self) -> str | None:
231
+ """Return the name of the current tag (e.g. div, p, img).
232
+
233
+ Returns
234
+ -------
235
+ text : str
236
+ """
237
+ ...
238
+ def decompose(self, recursive: bool = True) -> None:
239
+ """Remove the current node from the tree.
240
+
241
+ Parameters
242
+ ----------
243
+ recursive : bool, default True
244
+ Whenever to delete all its child nodes
245
+
246
+ Examples
247
+ --------
248
+
249
+ >>> tree = LexborHTMLParser(html)
250
+ >>> for tag in tree.css('script'):
251
+ >>> tag.decompose()
252
+ """
253
+ ...
254
+ def strip_tags(self, tags: list[str], recursive: bool = False) -> None:
255
+ """Remove specified tags from the HTML tree.
256
+
257
+ Parameters
258
+ ----------
259
+ tags : list
260
+ List of tags to remove.
261
+ recursive : bool, default True
262
+ Whenever to delete all its child nodes
263
+
264
+ Examples
265
+ --------
266
+
267
+ >>> tree = LexborHTMLParser('<html><head></head><body><script></script><div>Hello world!</div></body></html>')
268
+ >>> tags = ['head', 'style', 'script', 'xmp', 'iframe', 'noembed', 'noframes']
269
+ >>> tree.strip_tags(tags)
270
+ >>> tree.html
271
+ '<html><body><div>Hello world!</div></body></html>'
272
+ """
273
+ ...
96
274
  @property
97
- def attributes(self) -> dict[str, str | None]: ...
275
+ def attributes(self) -> dict[str, str | None]:
276
+ """Get all attributes that belong to the current node.
277
+
278
+ The value of empty attributes is None.
279
+
280
+ Returns
281
+ -------
282
+ attributes : dictionary of all attributes.
283
+
284
+ Examples
285
+ --------
286
+
287
+ >>> tree = LexborHTMLParser("<div data id='my_id'></div>")
288
+ >>> node = tree.css_first('div')
289
+ >>> node.attributes
290
+ {'data': None, 'id': 'my_id'}
291
+ """
292
+ ...
98
293
  @property
99
- def attrs(self) -> LexborAttributes: ...
294
+ def attrs(self) -> LexborAttributes:
295
+ """A dict-like object that is similar to the ``attributes`` property, but operates directly on the Node data.
296
+
297
+ .. warning:: Use ``attributes`` instead, if you don't want to modify Node attributes.
298
+
299
+ Returns
300
+ -------
301
+ attributes : Attributes mapping object.
302
+
303
+ Examples
304
+ --------
305
+
306
+ >>> tree = LexborHTMLParser("<div id='a'></div>")
307
+ >>> node = tree.css_first('div')
308
+ >>> node.attrs
309
+ <div attributes, 1 items>
310
+ >>> node.attrs['id']
311
+ 'a'
312
+ >>> node.attrs['foo'] = 'bar'
313
+ >>> del node.attrs['id']
314
+ >>> node.attributes
315
+ {'foo': 'bar'}
316
+ >>> node.attrs['id'] = 'new_id'
317
+ >>> node.html
318
+ '<div foo="bar" id="new_id"></div>'
319
+ """
320
+ ...
100
321
  @property
101
- def id(self) -> str | None: ...
102
- def iter(self, include_text: bool = False) -> Iterator[LexborNode]: ...
103
- def unwrap(self) -> None: ...
104
- def unwrap_tags(self, tags: list[str], delete_empty : bool = False) -> None: ...
105
- def traverse(self, include_text: bool = False) -> Iterator[LexborNode]: ...
106
- def replace_with(self, value: bytes | str | LexborNode) -> None: ...
107
- def insert_before(self, value: bytes | str | LexborNode) -> None: ...
108
- def insert_after(self, value: bytes | str | LexborNode) -> None: ...
109
- def insert_child(self, value: bytes | str | LexborNode) -> None: ...
322
+ def id(self) -> str | None:
323
+ """Get the id attribute of the node.
324
+
325
+ Returns None if id does not set.
326
+
327
+ Returns
328
+ -------
329
+ text : str
330
+ """
331
+ ...
332
+ def iter(self, include_text: bool = False) -> Iterator[LexborNode]:
333
+ """Iterate over nodes on the current level.
334
+
335
+ Parameters
336
+ ----------
337
+ include_text : bool
338
+ If True, includes text nodes as well.
339
+
340
+ Yields
341
+ -------
342
+ node
343
+ """
344
+ ...
345
+ def unwrap(self, delete_empty: bool = False) -> None:
346
+ """Replace node with whatever is inside this node.
347
+
348
+ Parameters
349
+ ----------
350
+ delete_empty : bool, default False
351
+ If True, removes empty tags.
352
+
353
+ Examples
354
+ --------
355
+
356
+ >>> tree = LexborHTMLParser("<div>Hello <i>world</i>!</div>")
357
+ >>> tree.css_first('i').unwrap()
358
+ >>> tree.html
359
+ '<html><head></head><body><div>Hello world!</div></body></html>'
360
+
361
+ Note: by default, empty tags are ignored, use "delete_empty" to change this.
362
+ """
363
+ ...
364
+ def unwrap_tags(self, tags: list[str], delete_empty: bool = False) -> None:
365
+ """Unwraps specified tags from the HTML tree.
366
+
367
+ Works the same as the ``unwrap`` method, but applied to a list of tags.
368
+
369
+ Parameters
370
+ ----------
371
+ tags : list
372
+ List of tags to remove.
373
+ delete_empty : bool, default False
374
+ If True, removes empty tags.
375
+
376
+ Examples
377
+ --------
378
+
379
+ >>> tree = LexborHTMLParser("<div><a href="">Hello</a> <i>world</i>!</div>")
380
+ >>> tree.body.unwrap_tags(['i','a'])
381
+ >>> tree.body.html
382
+ '<body><div>Hello world!</div></body>'
383
+
384
+ Note: by default, empty tags are ignored, use "delete_empty" to change this.
385
+ """
386
+ ...
387
+ def traverse(self, include_text: bool = False) -> Iterator[LexborNode]:
388
+ """Iterate over all child and next nodes starting from the current level.
389
+
390
+ Parameters
391
+ ----------
392
+ include_text : bool
393
+ If True, includes text nodes as well.
394
+
395
+ Yields
396
+ -------
397
+ node
398
+ """
399
+ ...
400
+ def replace_with(self, value: bytes | str | LexborNode) -> None:
401
+ """Replace current Node with specified value.
402
+
403
+ Parameters
404
+ ----------
405
+ value : str, bytes or Node
406
+ The text or Node instance to replace the Node with.
407
+ When a text string is passed, it's treated as text. All HTML tags will be escaped.
408
+ Convert and pass the ``Node`` object when you want to work with HTML.
409
+ Does not clone the ``Node`` object.
410
+ All future changes to the passed ``Node`` object will also be taken into account.
411
+
412
+ Examples
413
+ --------
414
+
415
+ >>> tree = LexborHTMLParser('<div>Get <img src="" alt="Laptop"></div>')
416
+ >>> img = tree.css_first('img')
417
+ >>> img.replace_with(img.attributes.get('alt', ''))
418
+ >>> tree.body.child.html
419
+ '<div>Get Laptop</div>'
420
+
421
+ >>> html_parser = LexborHTMLParser('<div>Get <span alt="Laptop"><img src="/jpg"> <div></div></span></div>')
422
+ >>> html_parser2 = LexborHTMLParser('<div>Test</div>')
423
+ >>> img_node = html_parser.css_first('img')
424
+ >>> img_node.replace_with(html_parser2.body.child)
425
+ '<div>Get <span alt="Laptop"><div>Test</div> <div></div></span></div>'
426
+ """
427
+ ...
428
+ def insert_before(self, value: bytes | str | LexborNode) -> None:
429
+ """Insert a node before the current Node.
430
+
431
+ Parameters
432
+ ----------
433
+ value : str, bytes or Node
434
+ The text or Node instance to insert before the Node.
435
+ When a text string is passed, it's treated as text. All HTML tags will be escaped.
436
+ Convert and pass the ``Node`` object when you want to work with HTML.
437
+ Does not clone the ``Node`` object.
438
+ All future changes to the passed ``Node`` object will also be taken into account.
439
+
440
+ Examples
441
+ --------
442
+
443
+ >>> tree = LexborHTMLParser('<div>Get <img src="" alt="Laptop"></div>')
444
+ >>> img = tree.css_first('img')
445
+ >>> img.insert_before(img.attributes.get('alt', ''))
446
+ >>> tree.body.child.html
447
+ '<div>Get Laptop<img src="" alt="Laptop"></div>'
448
+
449
+ >>> html_parser = LexborHTMLParser('<div>Get <span alt="Laptop"><img src="/jpg"> <div></div></span></div>')
450
+ >>> html_parser2 = LexborHTMLParser('<div>Test</div>')
451
+ >>> img_node = html_parser.css_first('img')
452
+ >>> img_node.insert_before(html_parser2.body.child)
453
+ <div>Get <span alt="Laptop"><div>Test</div><img src="/jpg"> <div></div></span></div>'
454
+ """
455
+ ...
456
+ def insert_after(self, value: bytes | str | LexborNode) -> None:
457
+ """Insert a node after the current Node.
458
+
459
+ Parameters
460
+ ----------
461
+ value : str, bytes or Node
462
+ The text or Node instance to insert after the Node.
463
+ When a text string is passed, it's treated as text. All HTML tags will be escaped.
464
+ Convert and pass the ``Node`` object when you want to work with HTML.
465
+ Does not clone the ``Node`` object.
466
+ All future changes to the passed ``Node`` object will also be taken into account.
467
+
468
+ Examples
469
+ --------
470
+
471
+ >>> tree = LexborHTMLParser('<div>Get <img src="" alt="Laptop"></div>')
472
+ >>> img = tree.css_first('img')
473
+ >>> img.insert_after(img.attributes.get('alt', ''))
474
+ >>> tree.body.child.html
475
+ '<div>Get <img src="" alt="Laptop">Laptop</div>'
476
+
477
+ >>> html_parser = LexborHTMLParser('<div>Get <span alt="Laptop"><img src="/jpg"> <div></div></span></div>')
478
+ >>> html_parser2 = LexborHTMLParser('<div>Test</div>')
479
+ >>> img_node = html_parser.css_first('img')
480
+ >>> img_node.insert_after(html_parser2.body.child)
481
+ <div>Get <span alt="Laptop"><img src="/jpg"><div>Test</div> <div></div></span></div>'
482
+ """
483
+ ...
484
+ def insert_child(self, value: bytes | str | LexborNode) -> None:
485
+ """Insert a node inside (at the end of) the current Node.
486
+
487
+ Parameters
488
+ ----------
489
+ value : str, bytes or Node
490
+ The text or Node instance to insert inside the Node.
491
+ When a text string is passed, it's treated as text. All HTML tags will be escaped.
492
+ Convert and pass the ``Node`` object when you want to work with HTML.
493
+ Does not clone the ``Node`` object.
494
+ All future changes to the passed ``Node`` object will also be taken into account.
495
+
496
+ Examples
497
+ --------
498
+
499
+ >>> tree = LexborHTMLParser('<div>Get <img src=""></div>')
500
+ >>> div = tree.css_first('div')
501
+ >>> div.insert_child('Laptop')
502
+ >>> tree.body.child.html
503
+ '<div>Get <img src="">Laptop</div>'
504
+
505
+ >>> html_parser = LexborHTMLParser('<div>Get <span alt="Laptop"> <div>Laptop</div> </span></div>')
506
+ >>> html_parser2 = LexborHTMLParser('<div>Test</div>')
507
+ >>> span_node = html_parser.css_first('span')
508
+ >>> span_node.insert_child(html_parser2.body.child)
509
+ <div>Get <span alt="Laptop"> <div>Laptop</div> <div>Test</div> </span></div>'
510
+ """
511
+ ...
110
512
  @property
111
- def raw_value(self) -> NoReturn: ...
112
- def scripts_contain(self, query: str) -> bool: ...
113
- def scripts_srcs_contain(self, queries: tuple[str]) -> bool: ...
114
- def remove(self, recursive: bool = True) -> None: ...
115
- def select(self, query: str | None = None) -> LexborSelector: ...
513
+ def raw_value(self) -> NoReturn:
514
+ """Return the raw (unparsed, original) value of a node.
515
+
516
+ Currently, works on text nodes only.
517
+
518
+ Returns
519
+ -------
520
+
521
+ raw_value : bytes
522
+
523
+ Examples
524
+ --------
525
+
526
+ >>> html_parser = LexborHTMLParser('<div>&#x3C;test&#x3E;</div>')
527
+ >>> selector = html_parser.css_first('div')
528
+ >>> selector.child.html
529
+ '&lt;test&gt;'
530
+ >>> selector.child.raw_value
531
+ b'&#x3C;test&#x3E;'
532
+ """
533
+ ...
534
+ def scripts_contain(self, query: str) -> bool:
535
+ """Returns True if any of the script tags contain specified text.
536
+
537
+ Caches script tags on the first call to improve performance.
538
+
539
+ Parameters
540
+ ----------
541
+ query : str
542
+ The query to check.
543
+ """
544
+ ...
545
+ def script_srcs_contain(self, queries: tuple[str]) -> bool:
546
+ """Returns True if any of the script SRCs attributes contain on of the specified text.
547
+
548
+ Caches values on the first call to improve performance.
549
+
550
+ Parameters
551
+ ----------
552
+ queries : tuple of str
553
+ """
554
+ ...
555
+ def remove(self, recursive: bool = True) -> None:
556
+ """An alias for the decompose method."""
557
+ ...
558
+ def select(self, query: str | None = None) -> LexborSelector:
559
+ """Select nodes given a CSS selector.
560
+
561
+ Works similarly to the the ``css`` method, but supports chained filtering and extra features.
562
+
563
+ Parameters
564
+ ----------
565
+ query : str or None
566
+ The CSS selector to use when searching for nodes.
567
+
568
+ Returns
569
+ -------
570
+ selector : The `Selector` class.
571
+ """
572
+ ...
116
573
  @property
117
- def text_content(self) -> str | None: ...
574
+ def text_content(self) -> str | None:
575
+ """Returns the text of the node if it is a text node.
576
+
577
+ Returns None for other nodes.
578
+ Unlike the ``text`` method, does not include child nodes.
579
+
580
+ Returns
581
+ -------
582
+ text : str or None.
583
+ """
584
+ ...
118
585
 
119
586
  class LexborHTMLParser:
120
- def __init__(self, html: str| bytes ): ...
587
+ """The lexbor HTML parser.
588
+
589
+ Use this class to parse raw HTML.
590
+
591
+ This parser mimics most of the stuff from ``HTMLParser`` but not inherits it directly.
592
+
593
+ Parameters
594
+ ----------
595
+
596
+ html : str (unicode) or bytes
597
+ """
598
+
599
+ def __init__(self, html: str | bytes): ...
121
600
  @property
122
601
  def selector(self) -> "LexborCSSSelector": ...
123
602
  @property
124
- def root(self) -> LexborNode | None: ...
603
+ def root(self) -> LexborNode | None:
604
+ """Returns root node."""
605
+ ...
125
606
  @property
126
- def body(self) -> LexborNode | None: ...
607
+ def body(self) -> LexborNode | None:
608
+ """Returns document body."""
609
+ ...
127
610
  @property
128
- def head(self) -> LexborNode | None: ...
129
- def tags(self, name: str) -> list[LexborNode]: ...
130
- def text(
131
- self, deep: bool = True, separator: str = "", strip: bool = False
132
- ) -> str: ...
611
+ def head(self) -> LexborNode | None:
612
+ """Returns document head."""
613
+ ...
614
+ def tags(self, name: str) -> list[LexborNode]:
615
+ """Returns a list of tags that match specified name.
616
+
617
+ Parameters
618
+ ----------
619
+ name : str (e.g. div)
620
+ """
621
+ ...
622
+ def text(self, deep: bool = True, separator: str = "", strip: bool = False) -> str:
623
+ """Returns the text of the node including text of all its child nodes.
624
+
625
+ Parameters
626
+ ----------
627
+ strip : bool, default False
628
+ If true, calls ``str.strip()`` on each text part to remove extra white spaces.
629
+ separator : str, default ''
630
+ The separator to use when joining text from different nodes.
631
+ deep : bool, default True
632
+ If True, includes text from all child nodes.
633
+
634
+ Returns
635
+ -------
636
+ text : str
637
+ """
638
+ ...
133
639
  @property
134
- def html(self) -> str | None: ...
135
- def css(self, query: str) -> list[LexborNode]: ...
640
+ def html(self) -> str | None:
641
+ """Return HTML representation of the page."""
642
+ ...
643
+ def css(self, query: str) -> list[LexborNode]:
644
+ """A CSS selector.
645
+
646
+ Matches pattern `query` against HTML tree.
647
+ `CSS selectors reference <https://www.w3schools.com/cssref/css_selectors.asp>`_.
648
+
649
+ Parameters
650
+ ----------
651
+ query : str
652
+ CSS selector (e.g. "div > :nth-child(2n+1):not(:has(a))").
653
+
654
+ Returns
655
+ -------
656
+ selector : list of `Node` objects
657
+ """
658
+ ...
136
659
  @overload
137
660
  def css_first(
138
661
  self, query: str, default: Any = ..., strict: Literal[True] = ...
139
- ) -> LexborNode: ...
662
+ ) -> LexborNode:
663
+ """Same as `css` but returns only the first match.
664
+
665
+ Parameters
666
+ ----------
667
+
668
+ query : str
669
+ default : bool, default None
670
+ Default value to return if there is no match.
671
+ strict: bool, default True
672
+ Set to True if you want to check if there is strictly only one match in the document.
673
+
674
+
675
+ Returns
676
+ -------
677
+ selector : `LexborNode` object
678
+ """
679
+ ...
140
680
  @overload
141
681
  def css_first(
142
682
  self, query: str, default: DefaultT, strict: bool = False
143
- ) -> LexborNode | DefaultT: ...
683
+ ) -> LexborNode | DefaultT:
684
+ """Same as `css` but returns only the first match.
685
+
686
+ Parameters
687
+ ----------
688
+
689
+ query : str
690
+ default : bool, default None
691
+ Default value to return if there is no match.
692
+ strict: bool, default True
693
+ Set to True if you want to check if there is strictly only one match in the document.
694
+
695
+
696
+ Returns
697
+ -------
698
+ selector : `LexborNode` object
699
+ """
700
+ ...
144
701
  @overload
145
702
  def css_first(
146
703
  self, query: str, default: None = ..., strict: bool = False
147
- ) -> LexborNode | None: ...
148
- def strip_tags(self, tags: list[str], recursive: bool = False) -> None: ...
149
- def select(self, query: str | None = None) -> LexborSelector | None: ...
150
- def any_css_matches(self, selectors: tuple[str]) -> bool: ...
151
- def scripts_contain(self, query: str) -> bool: ...
152
- def scripts_srcs_contain(self, queries: tuple[str]) -> bool: ...
704
+ ) -> LexborNode | None:
705
+ """Same as `css` but returns only the first match.
706
+
707
+ Parameters
708
+ ----------
709
+
710
+ query : str
711
+ default : bool, default None
712
+ Default value to return if there is no match.
713
+ strict: bool, default True
714
+ Set to True if you want to check if there is strictly only one match in the document.
715
+
716
+
717
+ Returns
718
+ -------
719
+ selector : `LexborNode` object
720
+ """
721
+ ...
722
+ def strip_tags(self, tags: list[str], recursive: bool = False) -> None:
723
+ """Remove specified tags from the node.
724
+
725
+ Parameters
726
+ ----------
727
+ tags : list of str
728
+ List of tags to remove.
729
+ recursive : bool, default True
730
+ Whenever to delete all its child nodes
731
+
732
+ Examples
733
+ --------
734
+
735
+ >>> tree = LexborHTMLParser('<html><head></head><body><script></script><div>Hello world!</div></body></html>')
736
+ >>> tags = ['head', 'style', 'script', 'xmp', 'iframe', 'noembed', 'noframes']
737
+ >>> tree.strip_tags(tags)
738
+ >>> tree.html
739
+ '<html><body><div>Hello world!</div></body></html>'
740
+ """
741
+ ...
742
+ def select(self, query: str | None = None) -> LexborSelector | None:
743
+ """Select nodes give a CSS selector.
744
+
745
+ Works similarly to the ``css`` method, but supports chained filtering and extra features.
746
+
747
+ Parameters
748
+ ----------
749
+ query : str or None
750
+ The CSS selector to use when searching for nodes.
751
+
752
+ Returns
753
+ -------
754
+ selector : The `Selector` class.
755
+ """
756
+ ...
757
+ def any_css_matches(self, selectors: tuple[str]) -> bool:
758
+ """Returns True if any of the specified CSS selectors matches a node."""
759
+ ...
760
+ def scripts_contain(self, query: str) -> bool:
761
+ """Returns True if any of the script tags contain specified text.
762
+
763
+ Caches script tags on the first call to improve performance.
764
+
765
+ Parameters
766
+ ----------
767
+ query : str
768
+ The query to check.
769
+ """
770
+ ...
771
+ def script_srcs_contain(self, queries: tuple[str]) -> bool:
772
+ """Returns True if any of the script SRCs attributes contain on of the specified text.
773
+
774
+ Caches values on the first call to improve performance.
775
+
776
+ Parameters
777
+ ----------
778
+ queries : tuple of str
779
+ """
780
+ ...
153
781
  def css_matches(self, selector: str) -> bool: ...
154
- def clone(self) -> LexborHTMLParser: ...
155
- def unwrap_tags(self, tags: list[str], delete_empty : bool = False) -> None: ...
782
+ def clone(self) -> LexborHTMLParser:
783
+ """Clone the current tree."""
784
+ ...
785
+ def unwrap_tags(self, tags: list[str], delete_empty: bool = False) -> None:
786
+ """Unwraps specified tags from the HTML tree.
787
+
788
+ Works the same as the ``unwrap`` method, but applied to a list of tags.
789
+
790
+ Parameters
791
+ ----------
792
+ tags : list
793
+ List of tags to remove.
794
+ delete_empty : bool
795
+ Whenever to delete empty tags.
796
+
797
+ Examples
798
+ --------
799
+
800
+ >>> tree = LexborHTMLParser("<div><a href="">Hello</a> <i>world</i>!</div>")
801
+ >>> tree.body.unwrap_tags(['i','a'])
802
+ >>> tree.body.html
803
+ '<body><div>Hello world!</div></body>'
804
+ """
805
+ ...
156
806
 
157
807
  def create_tag(tag: str) -> LexborNode:
158
808
  """
@@ -171,7 +821,7 @@ def parse_fragment(html: str) -> list[LexborNode]:
171
821
  """
172
822
  ...
173
823
 
174
-
175
824
  class SelectolaxError(Exception):
176
825
  """An exception that indicates error."""
826
+
177
827
  pass