selectolax 0.3.30__cp312-cp312-macosx_11_0_arm64.whl → 0.3.31__cp312-cp312-macosx_11_0_arm64.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,29 +77,84 @@ 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] = ...
@@ -84,55 +166,462 @@ class LexborNode:
84
166
  @overload
85
167
  def css_first(
86
168
  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: ...
169
+ ) -> LexborNode | None:
170
+ """Same as `css` but returns only the first match.
171
+
172
+ Parameters
173
+ ----------
174
+
175
+ query : str
176
+ default : bool, default None
177
+ Default value to return if there is no match.
178
+ strict: bool, default True
179
+ Set to True if you want to check if there is strictly only one match in the document.
180
+
181
+
182
+ Returns
183
+ -------
184
+ selector : `LexborNode` object
185
+ """
186
+ ...
187
+ def any_css_matches(self, selectors: tuple[str]) -> bool:
188
+ """Returns True if any of CSS selectors matches a node"""
189
+ ...
190
+ def css_matches(self, selector: str) -> bool:
191
+ """Returns True if CSS selector matches a node."""
192
+ ...
90
193
  @property
91
194
  def tag_id(self) -> int: ...
92
195
  @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: ...
196
+ def tag(self) -> str | None:
197
+ """Return the name of the current tag (e.g. div, p, img).
198
+
199
+ Returns
200
+ -------
201
+ text : str
202
+ """
203
+ ...
204
+ def decompose(self, recursive: bool = True) -> None:
205
+ """Remove the current node from the tree.
206
+
207
+ Parameters
208
+ ----------
209
+ recursive : bool, default True
210
+ Whenever to delete all its child nodes
211
+
212
+ Examples
213
+ --------
214
+
215
+ >>> tree = LexborHTMLParser(html)
216
+ >>> for tag in tree.css('script'):
217
+ >>> tag.decompose()
218
+ """
219
+ ...
220
+ def strip_tags(self, tags: list[str], recursive: bool = False) -> None:
221
+ """Remove specified tags from the HTML tree.
222
+
223
+ Parameters
224
+ ----------
225
+ tags : list
226
+ List of tags to remove.
227
+ recursive : bool, default True
228
+ Whenever to delete all its child nodes
229
+
230
+ Examples
231
+ --------
232
+
233
+ >>> tree = LexborHTMLParser('<html><head></head><body><script></script><div>Hello world!</div></body></html>')
234
+ >>> tags = ['head', 'style', 'script', 'xmp', 'iframe', 'noembed', 'noframes']
235
+ >>> tree.strip_tags(tags)
236
+ >>> tree.html
237
+ '<html><body><div>Hello world!</div></body></html>'
238
+ """
239
+ ...
96
240
  @property
97
- def attributes(self) -> dict[str, str | None]: ...
241
+ def attributes(self) -> dict[str, str | None]:
242
+ """Get all attributes that belong to the current node.
243
+
244
+ The value of empty attributes is None.
245
+
246
+ Returns
247
+ -------
248
+ attributes : dictionary of all attributes.
249
+
250
+ Examples
251
+ --------
252
+
253
+ >>> tree = LexborHTMLParser("<div data id='my_id'></div>")
254
+ >>> node = tree.css_first('div')
255
+ >>> node.attributes
256
+ {'data': None, 'id': 'my_id'}
257
+ """
258
+ ...
98
259
  @property
99
- def attrs(self) -> LexborAttributes: ...
260
+ def attrs(self) -> LexborAttributes:
261
+ """A dict-like object that is similar to the ``attributes`` property, but operates directly on the Node data.
262
+
263
+ .. warning:: Use ``attributes`` instead, if you don't want to modify Node attributes.
264
+
265
+ Returns
266
+ -------
267
+ attributes : Attributes mapping object.
268
+
269
+ Examples
270
+ --------
271
+
272
+ >>> tree = LexborHTMLParser("<div id='a'></div>")
273
+ >>> node = tree.css_first('div')
274
+ >>> node.attrs
275
+ <div attributes, 1 items>
276
+ >>> node.attrs['id']
277
+ 'a'
278
+ >>> node.attrs['foo'] = 'bar'
279
+ >>> del node.attrs['id']
280
+ >>> node.attributes
281
+ {'foo': 'bar'}
282
+ >>> node.attrs['id'] = 'new_id'
283
+ >>> node.html
284
+ '<div foo="bar" id="new_id"></div>'
285
+ """
286
+ ...
100
287
  @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: ...
288
+ def id(self) -> str | None:
289
+ """Get the id attribute of the node.
290
+
291
+ Returns None if id does not set.
292
+
293
+ Returns
294
+ -------
295
+ text : str
296
+ """
297
+ ...
298
+ def iter(self, include_text: bool = False) -> Iterator[LexborNode]:
299
+ """Iterate over nodes on the current level.
300
+
301
+ Parameters
302
+ ----------
303
+ include_text : bool
304
+ If True, includes text nodes as well.
305
+
306
+ Yields
307
+ -------
308
+ node
309
+ """
310
+ ...
311
+ def unwrap(self, delete_empty: bool = False) -> None:
312
+ """Replace node with whatever is inside this node.
313
+
314
+ Parameters
315
+ ----------
316
+ delete_empty : bool, default False
317
+ If True, removes empty tags.
318
+
319
+ Examples
320
+ --------
321
+
322
+ >>> tree = LexborHTMLParser("<div>Hello <i>world</i>!</div>")
323
+ >>> tree.css_first('i').unwrap()
324
+ >>> tree.html
325
+ '<html><head></head><body><div>Hello world!</div></body></html>'
326
+
327
+ Note: by default, empty tags are ignored, use "delete_empty" to change this.
328
+ """
329
+ ...
330
+ def unwrap_tags(self, tags: list[str], delete_empty: bool = False) -> None:
331
+ """Unwraps specified tags from the HTML tree.
332
+
333
+ Works the same as the ``unwrap`` method, but applied to a list of tags.
334
+
335
+ Parameters
336
+ ----------
337
+ tags : list
338
+ List of tags to remove.
339
+ delete_empty : bool, default False
340
+ If True, removes empty tags.
341
+
342
+ Examples
343
+ --------
344
+
345
+ >>> tree = LexborHTMLParser("<div><a href="">Hello</a> <i>world</i>!</div>")
346
+ >>> tree.body.unwrap_tags(['i','a'])
347
+ >>> tree.body.html
348
+ '<body><div>Hello world!</div></body>'
349
+
350
+ Note: by default, empty tags are ignored, use "delete_empty" to change this.
351
+ """
352
+ ...
353
+ def traverse(self, include_text: bool = False) -> Iterator[LexborNode]:
354
+ """Iterate over all child and next nodes starting from the current level.
355
+
356
+ Parameters
357
+ ----------
358
+ include_text : bool
359
+ If True, includes text nodes as well.
360
+
361
+ Yields
362
+ -------
363
+ node
364
+ """
365
+ ...
366
+ def replace_with(self, value: bytes | str | LexborNode) -> None:
367
+ """Replace current Node with specified value.
368
+
369
+ Parameters
370
+ ----------
371
+ value : str, bytes or Node
372
+ The text or Node instance to replace the Node with.
373
+ When a text string is passed, it's treated as text. All HTML tags will be escaped.
374
+ Convert and pass the ``Node`` object when you want to work with HTML.
375
+ Does not clone the ``Node`` object.
376
+ All future changes to the passed ``Node`` object will also be taken into account.
377
+
378
+ Examples
379
+ --------
380
+
381
+ >>> tree = LexborHTMLParser('<div>Get <img src="" alt="Laptop"></div>')
382
+ >>> img = tree.css_first('img')
383
+ >>> img.replace_with(img.attributes.get('alt', ''))
384
+ >>> tree.body.child.html
385
+ '<div>Get Laptop</div>'
386
+
387
+ >>> html_parser = LexborHTMLParser('<div>Get <span alt="Laptop"><img src="/jpg"> <div></div></span></div>')
388
+ >>> html_parser2 = LexborHTMLParser('<div>Test</div>')
389
+ >>> img_node = html_parser.css_first('img')
390
+ >>> img_node.replace_with(html_parser2.body.child)
391
+ '<div>Get <span alt="Laptop"><div>Test</div> <div></div></span></div>'
392
+ """
393
+ ...
394
+ def insert_before(self, value: bytes | str | LexborNode) -> None:
395
+ """Insert a node before the current Node.
396
+
397
+ Parameters
398
+ ----------
399
+ value : str, bytes or Node
400
+ The text or Node instance to insert before the Node.
401
+ When a text string is passed, it's treated as text. All HTML tags will be escaped.
402
+ Convert and pass the ``Node`` object when you want to work with HTML.
403
+ Does not clone the ``Node`` object.
404
+ All future changes to the passed ``Node`` object will also be taken into account.
405
+
406
+ Examples
407
+ --------
408
+
409
+ >>> tree = LexborHTMLParser('<div>Get <img src="" alt="Laptop"></div>')
410
+ >>> img = tree.css_first('img')
411
+ >>> img.insert_before(img.attributes.get('alt', ''))
412
+ >>> tree.body.child.html
413
+ '<div>Get Laptop<img src="" alt="Laptop"></div>'
414
+
415
+ >>> html_parser = LexborHTMLParser('<div>Get <span alt="Laptop"><img src="/jpg"> <div></div></span></div>')
416
+ >>> html_parser2 = LexborHTMLParser('<div>Test</div>')
417
+ >>> img_node = html_parser.css_first('img')
418
+ >>> img_node.insert_before(html_parser2.body.child)
419
+ <div>Get <span alt="Laptop"><div>Test</div><img src="/jpg"> <div></div></span></div>'
420
+ """
421
+ ...
422
+ def insert_after(self, value: bytes | str | LexborNode) -> None:
423
+ """Insert a node after the current Node.
424
+
425
+ Parameters
426
+ ----------
427
+ value : str, bytes or Node
428
+ The text or Node instance to insert after the Node.
429
+ When a text string is passed, it's treated as text. All HTML tags will be escaped.
430
+ Convert and pass the ``Node`` object when you want to work with HTML.
431
+ Does not clone the ``Node`` object.
432
+ All future changes to the passed ``Node`` object will also be taken into account.
433
+
434
+ Examples
435
+ --------
436
+
437
+ >>> tree = LexborHTMLParser('<div>Get <img src="" alt="Laptop"></div>')
438
+ >>> img = tree.css_first('img')
439
+ >>> img.insert_after(img.attributes.get('alt', ''))
440
+ >>> tree.body.child.html
441
+ '<div>Get <img src="" alt="Laptop">Laptop</div>'
442
+
443
+ >>> html_parser = LexborHTMLParser('<div>Get <span alt="Laptop"><img src="/jpg"> <div></div></span></div>')
444
+ >>> html_parser2 = LexborHTMLParser('<div>Test</div>')
445
+ >>> img_node = html_parser.css_first('img')
446
+ >>> img_node.insert_after(html_parser2.body.child)
447
+ <div>Get <span alt="Laptop"><img src="/jpg"><div>Test</div> <div></div></span></div>'
448
+ """
449
+ ...
450
+ def insert_child(self, value: bytes | str | LexborNode) -> None:
451
+ """Insert a node inside (at the end of) the current Node.
452
+
453
+ Parameters
454
+ ----------
455
+ value : str, bytes or Node
456
+ The text or Node instance to insert inside the Node.
457
+ When a text string is passed, it's treated as text. All HTML tags will be escaped.
458
+ Convert and pass the ``Node`` object when you want to work with HTML.
459
+ Does not clone the ``Node`` object.
460
+ All future changes to the passed ``Node`` object will also be taken into account.
461
+
462
+ Examples
463
+ --------
464
+
465
+ >>> tree = LexborHTMLParser('<div>Get <img src=""></div>')
466
+ >>> div = tree.css_first('div')
467
+ >>> div.insert_child('Laptop')
468
+ >>> tree.body.child.html
469
+ '<div>Get <img src="">Laptop</div>'
470
+
471
+ >>> html_parser = LexborHTMLParser('<div>Get <span alt="Laptop"> <div>Laptop</div> </span></div>')
472
+ >>> html_parser2 = LexborHTMLParser('<div>Test</div>')
473
+ >>> span_node = html_parser.css_first('span')
474
+ >>> span_node.insert_child(html_parser2.body.child)
475
+ <div>Get <span alt="Laptop"> <div>Laptop</div> <div>Test</div> </span></div>'
476
+ """
477
+ ...
110
478
  @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: ...
479
+ def raw_value(self) -> NoReturn:
480
+ """Return the raw (unparsed, original) value of a node.
481
+
482
+ Currently, works on text nodes only.
483
+
484
+ Returns
485
+ -------
486
+
487
+ raw_value : bytes
488
+
489
+ Examples
490
+ --------
491
+
492
+ >>> html_parser = LexborHTMLParser('<div>&#x3C;test&#x3E;</div>')
493
+ >>> selector = html_parser.css_first('div')
494
+ >>> selector.child.html
495
+ '&lt;test&gt;'
496
+ >>> selector.child.raw_value
497
+ b'&#x3C;test&#x3E;'
498
+ """
499
+ ...
500
+ def scripts_contain(self, query: str) -> bool:
501
+ """Returns True if any of the script tags contain specified text.
502
+
503
+ Caches script tags on the first call to improve performance.
504
+
505
+ Parameters
506
+ ----------
507
+ query : str
508
+ The query to check.
509
+ """
510
+ ...
511
+ def script_srcs_contain(self, queries: tuple[str]) -> bool:
512
+ """Returns True if any of the script SRCs attributes contain on of the specified text.
513
+
514
+ Caches values on the first call to improve performance.
515
+
516
+ Parameters
517
+ ----------
518
+ queries : tuple of str
519
+ """
520
+ ...
521
+ def remove(self, recursive: bool = True) -> None:
522
+ """An alias for the decompose method."""
523
+ ...
524
+ def select(self, query: str | None = None) -> LexborSelector:
525
+ """Select nodes given a CSS selector.
526
+
527
+ Works similarly to the the ``css`` method, but supports chained filtering and extra features.
528
+
529
+ Parameters
530
+ ----------
531
+ query : str or None
532
+ The CSS selector to use when searching for nodes.
533
+
534
+ Returns
535
+ -------
536
+ selector : The `Selector` class.
537
+ """
538
+ ...
116
539
  @property
117
- def text_content(self) -> str | None: ...
540
+ def text_content(self) -> str | None:
541
+ """Returns the text of the node if it is a text node.
542
+
543
+ Returns None for other nodes.
544
+ Unlike the ``text`` method, does not include child nodes.
545
+
546
+ Returns
547
+ -------
548
+ text : str or None.
549
+ """
550
+ ...
118
551
 
119
552
  class LexborHTMLParser:
120
- def __init__(self, html: str| bytes ): ...
553
+ """The lexbor HTML parser.
554
+
555
+ Use this class to parse raw HTML.
556
+
557
+ This parser mimics most of the stuff from ``HTMLParser`` but not inherits it directly.
558
+
559
+ Parameters
560
+ ----------
561
+
562
+ html : str (unicode) or bytes
563
+ """
564
+
565
+ def __init__(self, html: str | bytes): ...
121
566
  @property
122
567
  def selector(self) -> "LexborCSSSelector": ...
123
568
  @property
124
- def root(self) -> LexborNode | None: ...
569
+ def root(self) -> LexborNode | None:
570
+ """Returns root node."""
571
+ ...
125
572
  @property
126
- def body(self) -> LexborNode | None: ...
573
+ def body(self) -> LexborNode | None:
574
+ """Returns document body."""
575
+ ...
127
576
  @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: ...
577
+ def head(self) -> LexborNode | None:
578
+ """Returns document head."""
579
+ ...
580
+ def tags(self, name: str) -> list[LexborNode]:
581
+ """Returns a list of tags that match specified name.
582
+
583
+ Parameters
584
+ ----------
585
+ name : str (e.g. div)
586
+ """
587
+ ...
588
+ def text(self, deep: bool = True, separator: str = "", strip: bool = False) -> str:
589
+ """Returns the text of the node including text of all its child nodes.
590
+
591
+ Parameters
592
+ ----------
593
+ strip : bool, default False
594
+ If true, calls ``str.strip()`` on each text part to remove extra white spaces.
595
+ separator : str, default ''
596
+ The separator to use when joining text from different nodes.
597
+ deep : bool, default True
598
+ If True, includes text from all child nodes.
599
+
600
+ Returns
601
+ -------
602
+ text : str
603
+ """
604
+ ...
133
605
  @property
134
- def html(self) -> str | None: ...
135
- def css(self, query: str) -> list[LexborNode]: ...
606
+ def html(self) -> str | None:
607
+ """Return HTML representation of the page."""
608
+ ...
609
+ def css(self, query: str) -> list[LexborNode]:
610
+ """A CSS selector.
611
+
612
+ Matches pattern `query` against HTML tree.
613
+ `CSS selectors reference <https://www.w3schools.com/cssref/css_selectors.asp>`_.
614
+
615
+ Parameters
616
+ ----------
617
+ query : str
618
+ CSS selector (e.g. "div > :nth-child(2n+1):not(:has(a))").
619
+
620
+ Returns
621
+ -------
622
+ selector : list of `Node` objects
623
+ """
624
+ ...
136
625
  @overload
137
626
  def css_first(
138
627
  self, query: str, default: Any = ..., strict: Literal[True] = ...
@@ -144,15 +633,108 @@ class LexborHTMLParser:
144
633
  @overload
145
634
  def css_first(
146
635
  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: ...
636
+ ) -> LexborNode | None:
637
+ """Same as `css` but returns only the first match.
638
+
639
+ Parameters
640
+ ----------
641
+
642
+ query : str
643
+ default : bool, default None
644
+ Default value to return if there is no match.
645
+ strict: bool, default True
646
+ Set to True if you want to check if there is strictly only one match in the document.
647
+
648
+
649
+ Returns
650
+ -------
651
+ selector : `LexborNode` object
652
+ """
653
+ ...
654
+ def strip_tags(self, tags: list[str], recursive: bool = False) -> None:
655
+ """Remove specified tags from the node.
656
+
657
+ Parameters
658
+ ----------
659
+ tags : list of str
660
+ List of tags to remove.
661
+ recursive : bool, default True
662
+ Whenever to delete all its child nodes
663
+
664
+ Examples
665
+ --------
666
+
667
+ >>> tree = LexborHTMLParser('<html><head></head><body><script></script><div>Hello world!</div></body></html>')
668
+ >>> tags = ['head', 'style', 'script', 'xmp', 'iframe', 'noembed', 'noframes']
669
+ >>> tree.strip_tags(tags)
670
+ >>> tree.html
671
+ '<html><body><div>Hello world!</div></body></html>'
672
+ """
673
+ ...
674
+ def select(self, query: str | None = None) -> LexborSelector | None:
675
+ """Select nodes give a CSS selector.
676
+
677
+ Works similarly to the ``css`` method, but supports chained filtering and extra features.
678
+
679
+ Parameters
680
+ ----------
681
+ query : str or None
682
+ The CSS selector to use when searching for nodes.
683
+
684
+ Returns
685
+ -------
686
+ selector : The `Selector` class.
687
+ """
688
+ ...
689
+ def any_css_matches(self, selectors: tuple[str]) -> bool:
690
+ """Returns True if any of the specified CSS selectors matches a node."""
691
+ ...
692
+ def scripts_contain(self, query: str) -> bool:
693
+ """Returns True if any of the script tags contain specified text.
694
+
695
+ Caches script tags on the first call to improve performance.
696
+
697
+ Parameters
698
+ ----------
699
+ query : str
700
+ The query to check.
701
+ """
702
+ ...
703
+ def script_srcs_contain(self, queries: tuple[str]) -> bool:
704
+ """Returns True if any of the script SRCs attributes contain on of the specified text.
705
+
706
+ Caches values on the first call to improve performance.
707
+
708
+ Parameters
709
+ ----------
710
+ queries : tuple of str
711
+ """
712
+ ...
153
713
  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: ...
714
+ def clone(self) -> LexborHTMLParser:
715
+ """Clone the current tree."""
716
+ ...
717
+ def unwrap_tags(self, tags: list[str], delete_empty: bool = False) -> None:
718
+ """Unwraps specified tags from the HTML tree.
719
+
720
+ Works the same as the ``unwrap`` method, but applied to a list of tags.
721
+
722
+ Parameters
723
+ ----------
724
+ tags : list
725
+ List of tags to remove.
726
+ delete_empty : bool
727
+ Whenever to delete empty tags.
728
+
729
+ Examples
730
+ --------
731
+
732
+ >>> tree = LexborHTMLParser("<div><a href="">Hello</a> <i>world</i>!</div>")
733
+ >>> tree.body.unwrap_tags(['i','a'])
734
+ >>> tree.body.html
735
+ '<body><div>Hello world!</div></body>'
736
+ """
737
+ ...
156
738
 
157
739
  def create_tag(tag: str) -> LexborNode:
158
740
  """
@@ -171,7 +753,7 @@ def parse_fragment(html: str) -> list[LexborNode]:
171
753
  """
172
754
  ...
173
755
 
174
-
175
756
  class SelectolaxError(Exception):
176
757
  """An exception that indicates error."""
758
+
177
759
  pass