-
Notifications
You must be signed in to change notification settings - Fork 285
Expand file tree
/
Copy pathHtmlOperations.fs
More file actions
864 lines (719 loc) · 37 KB
/
HtmlOperations.fs
File metadata and controls
864 lines (719 loc) · 37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
namespace FSharp.Data
open System
open FSharp.Data
open System.Runtime.CompilerServices
[<AutoOpen>]
module private Utils =
let inline toLower (s: string) = s.ToLowerInvariant()
let inline getNameSet names = names |> Seq.map toLower |> Set.ofSeq
// --------------------------------------------------------------------------------------
[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
/// Module with operations on HTML attributes
module HtmlAttribute =
/// Gets the name of the given attribute
let name attr =
match attr with
| HtmlAttribute(name = name) -> name
/// Gets the value of the given attribute
let value attr =
match attr with
| HtmlAttribute(value = value) -> value
// --------------------------------------------------------------------------------------
[<Extension>]
/// Extension methods with operations on HTML attributes
type HtmlAttributeExtensions =
/// Gets the name of the current attribute
[<Extension>]
static member Name(attr: HtmlAttribute) = HtmlAttribute.name attr
/// Gets the value of the current attribute
[<Extension>]
static member Value(attr: HtmlAttribute) = HtmlAttribute.value attr
// --------------------------------------------------------------------------------------
[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
/// Module with operations on HTML nodes
module HtmlNode =
/// Gets the given nodes name
let name n =
match n with
| HtmlNode.HtmlElement(name = name) -> name
| _ -> ""
/// Gets all of the nodes immediately under this node
let elements n =
match n with
| HtmlNode.HtmlElement(elements = elements) -> elements
| _ -> []
/// <summary>
/// Finds all of the elements nodes of this node that match the given set of names
/// </summary>
/// <param name="names">The set of names to match</param>
/// <param name="n">The given node</param>
let inline elementsNamed names n =
let nameSet = getNameSet names
n |> elements |> List.filter (name >> nameSet.Contains)
let private descendantsBy includeSelf recurseOnMatch predicate n =
let rec descendantsBy includeSelf n =
seq {
let proceed = ref true
if includeSelf && predicate n then
yield n
if not recurseOnMatch then
proceed := false
if !proceed then
for element in elements n do
yield! descendantsBy true element
}
descendantsBy includeSelf n
/// <summary>
/// Gets all of the descendants of this node that statisfy the given predicate
/// </summary>
/// <param name="recurseOnMatch">If a match is found continues down the tree matching child elements</param>
/// <param name="predicate">The predicate by which to match the nodes to return</param>
/// <param name="n">The given node</param>
let descendants recurseOnMatch predicate n =
descendantsBy false recurseOnMatch predicate n
/// <summary>
/// Gets all of the descendants of this node that statisfy the given predicate
/// The current node is also considered in the comparison
/// </summary>
/// <param name="recurseOnMatch">If a match is found continues down the tree matching child elements</param>
/// <param name="predicate">The predicate by which to match the nodes to return</param>
/// <param name="n">The given node</param>
let descendantsAndSelf recurseOnMatch predicate n =
descendantsBy true recurseOnMatch predicate n
/// <summary>
/// Finds all of the descendant nodes of this nodes that match the given set of names
/// </summary>
/// <param name="recurseOnMatch">If a match is found continues down the tree matching child elements</param>
/// <param name="names">The set of names to match</param>
/// <param name="n">The given node</param>
let inline descendantsNamed recurseOnMatch names n =
let nameSet = getNameSet names
n |> descendants recurseOnMatch (name >> nameSet.Contains)
/// <summary>
/// Finds all of the descendant nodes of this nodes that match the given set of names
/// The current node is also considered in the comparison
/// </summary>
/// <param name="recurseOnMatch">If a match is found continues down the tree matching child elements</param>
/// <param name="names">The set of names to match</param>
/// <param name="n">The given node</param>
let inline descendantsAndSelfNamed recurseOnMatch names n =
let nameSet = getNameSet names
n |> descendantsAndSelf recurseOnMatch (name >> nameSet.Contains)
let private descendantsByWithPath includeSelf recurseOnMatch predicate n =
let rec descendantsByWithPath includeSelf path n =
seq {
let proceed = ref true
if includeSelf && predicate n then
yield n, path
if not recurseOnMatch then
proceed := false
if !proceed then
for element in elements n do
yield! descendantsByWithPath true (n :: path) element
}
descendantsByWithPath includeSelf [] n
/// <summary>
/// Gets all of the descendants of this node that statisfy the given predicate
/// </summary>
/// <param name="recurseOnMatch">If a match is found continues down the tree matching child elements</param>
/// <param name="predicate">The predicate by which to match the nodes to return</param>
/// <param name="n">The given node</param>
let descendantsWithPath recurseOnMatch predicate n =
descendantsByWithPath false recurseOnMatch predicate n
/// <summary>
/// Gets all of the descendants of this node that statisfy the given predicate
/// The current node is also considered in the comparison
/// </summary>
/// <param name="recurseOnMatch">If a match is found continues down the tree matching child elements</param>
/// <param name="predicate">The predicate by which to match the nodes to return</param>
/// <param name="n">The given node</param>
let descendantsAndSelfWithPath recurseOnMatch predicate n =
descendantsByWithPath true recurseOnMatch predicate n
/// <summary>
/// Finds all of the descendant nodes of this nodes that match the given set of names
/// </summary>
/// <param name="recurseOnMatch">If a match is found continues down the tree matching child elements</param>
/// <param name="names">The set of names to match</param>
/// <param name="n">The given node</param>
let inline descendantsNamedWithPath recurseOnMatch names n =
let nameSet = getNameSet names
n |> descendantsWithPath recurseOnMatch (name >> nameSet.Contains)
/// <summary>
/// Finds all of the descendant nodes of this nodes that match the given set of names
/// The current node is also considered in the comparison
/// </summary>
/// <param name="recurseOnMatch">If a match is found continues down the tree matching child elements</param>
/// <param name="names">The set of names to match</param>
/// <param name="n">The given node</param>
let inline descendantsAndSelfNamedWithPath recurseOnMatch names n =
let nameSet = getNameSet names
n |> descendantsAndSelfWithPath recurseOnMatch (name >> nameSet.Contains)
/// Gets all of the attributes of this node
let attributes n =
match n with
| HtmlNode.HtmlElement(attributes = attributes) -> attributes
| _ -> []
/// <summary>
/// Tries to return an attribute that exists on the current node
/// </summary>
/// <param name="name">The name of the attribute to return.</param>
/// <param name="n">The given node</param>
let inline tryGetAttribute name n =
n |> attributes |> List.tryFind (HtmlAttribute.name >> ((=) (toLower name)))
/// <summary>
/// Returns the attribute with the given name. If the
/// attribute does not exist then this will throw an exception
/// </summary>
/// <param name="name">The name of the attribute to select</param>
/// <param name="n">The given node</param>
let inline attribute name n =
match tryGetAttribute name n with
| Some v -> v
| None -> failwithf "Unable to find attribute (%s)" name
/// <summary>
/// Return the value of the named attribute, or an empty string if not found.
/// </summary>
/// <param name="name">The name of the attribute to get the value from</param>
/// <param name="n">The given node</param>
let inline attributeValue name n =
defaultArg (n |> tryGetAttribute name |> Option.map HtmlAttribute.value) ""
/// <summary>
/// Returns true if the current node has an attribute that
/// matches both the name and the value
/// </summary>
/// <param name="name">The name of the attribute</param>
/// <param name="value">The value of the attribute</param>
/// <param name="n">The given html node</param>
let inline hasAttribute name value n =
match tryGetAttribute name n with
| Some attr -> toLower (HtmlAttribute.value attr) = toLower value
| None -> false
/// Returns true if the current node has the specified name
let inline hasName (expectedName: string) n =
name n = expectedName.ToLowerInvariant()
/// Returns true if the current node has the specified id
let inline hasId id n = hasAttribute "id" id n
/// Returns true if the current node has the specified class
let inline hasClass (cssClass: string) n =
let presentClasses = (attributeValue "class" n).Split [| ' ' |]
let classesToLookFor = cssClass.Split [| ' ' |]
classesToLookFor
|> Array.forall (fun cssClass -> presentClasses |> Array.exists ((=) cssClass))
let private innerTextExcluding' recurse exclusions n =
let rec innerText' n =
match n with
| HtmlNode.HtmlElement(name, _, content) when List.forall ((<>) name) exclusions ->
seq {
for e in content do
match e with
| HtmlNode.HtmlText(text) -> yield text
| HtmlNode.HtmlComment(_) -> yield ""
| elem -> if recurse then yield innerText' elem else yield ""
}
|> String.Concat
| HtmlNode.HtmlText(text) -> text
| _ -> ""
innerText' n
let innerTextExcluding exclusions n = innerTextExcluding' true exclusions n
/// <summary>
/// Returns the inner text of the current node
/// </summary>
/// <param name="n">The given node</param>
let inline innerText n = innerTextExcluding [] n
/// <summary>
/// Returns the direct inner text of the current node
/// </summary>
/// <param name="n">The given node</param>
let directInnerText n = innerTextExcluding' false [] n
open HtmlCssSelectors
let private getTargets level matched =
match level with
| FilterLevel.Children -> matched |> Seq.collect elements
| FilterLevel.Descendants -> matched |> Seq.collect (descendants true (fun _ -> true))
| _ -> matched |> Seq.ofList
let private searchTag level matched tag =
match level with
| Children -> matched |> List.collect (elementsNamed [ tag ])
| _ -> matched |> Seq.collect (descendantsAndSelfNamed true [ tag ]) |> Seq.toList
let private filterByAttr level matched attr f =
matched
|> getTargets level
|> Seq.filter (attributeValue attr >> f)
|> Seq.toList
let private attrExists level matched attr =
matched
|> getTargets level
|> Seq.filter (attributes >> Seq.exists (HtmlAttribute.name >> (=) attr))
|> Seq.toList
let private selectCssElements tokens nodes =
let whiteSpaces = [| ' '; '\t'; '\r'; '\n' |]
let rec selectElements' level acc source =
// if we already have an empty list, terminate early
if List.isEmpty acc then
[]
else
let selectDescendantOfType ty t =
let selectedNodes = filterByAttr level acc "type" (fun v -> v = ty)
selectElements' FilterLevel.Root selectedNodes t
let selectEvenOdd (isEven: bool) =
acc
|> List.mapi (fun i n -> (i, n))
|> List.filter (fun (i, _) ->
match isEven with
| true -> i % 2 = 0
| false -> i % 2 <> 0)
|> List.map (fun (_, n) -> n)
let containsIgnoreCase (value: string) (word: string) =
word.IndexOf(value, StringComparison.OrdinalIgnoreCase) <> -1
let equalsIgnoreCase (value: string) (word: string) =
word.Equals(value, StringComparison.OrdinalIgnoreCase)
match source with
| TagName(_, name) :: t ->
let selectedNodes = searchTag level acc name
selectElements' FilterLevel.Root selectedNodes t
| ClassPrefix _ :: CssClass(_, className) :: t ->
let selectedNodes =
filterByAttr level acc "class" (fun v -> v.Split(whiteSpaces) |> Array.exists ((=) className))
selectElements' FilterLevel.Root selectedNodes t
| IdPrefix _ :: CssId(_, id) :: t ->
let selectedNodes = filterByAttr level acc "id" (fun v -> v = id)
selectElements' FilterLevel.Root selectedNodes t
| OpenAttribute _ :: AttributeName(_, name) :: Assign _ :: AttributeValue(_, value) :: CloseAttribute _ :: t ->
let selectedNodes = filterByAttr level acc name (fun v -> v = value)
selectElements' FilterLevel.Root selectedNodes t
| OpenAttribute _ :: AttributeName(_, name) :: EndWith _ :: AttributeValue(_, value) :: CloseAttribute _ :: t ->
let selectedNodes =
filterByAttr level acc name (fun v -> v.EndsWith(value, StringComparison.Ordinal))
selectElements' FilterLevel.Root selectedNodes t
| OpenAttribute _ :: AttributeName(_, name) :: StartWith _ :: AttributeValue(_, value) :: CloseAttribute _ :: t ->
let selectedNodes =
filterByAttr level acc name (fun v -> v.StartsWith(value, StringComparison.Ordinal))
selectElements' FilterLevel.Root selectedNodes t
| OpenAttribute _ :: AttributeName(_, name) :: AttributeContainsPrefix _ :: AttributeValue(_, value) :: CloseAttribute _ :: t ->
let selectedNodes =
filterByAttr level acc name (fun v ->
let chars =
v
|> Seq.skipWhile (fun c -> c = '\'')
|> Seq.takeWhile Char.IsLetter
|> Seq.toArray
let s = new String(chars)
s = value)
selectElements' FilterLevel.Root selectedNodes t
| OpenAttribute _ :: AttributeName(_, name) :: AttributeContains _ :: AttributeValue(_, value) :: CloseAttribute _ :: t ->
let selectedNodes = filterByAttr level acc name (containsIgnoreCase value)
selectElements' FilterLevel.Root selectedNodes t
| OpenAttribute _ :: AttributeName(_, name) :: AttributeContainsWord _ :: AttributeValue(_, value) :: CloseAttribute _ :: t ->
let selectedNodes =
filterByAttr level acc name (fun v ->
v.Split(whiteSpaces) |> Array.exists (equalsIgnoreCase value))
selectElements' FilterLevel.Root selectedNodes t
| OpenAttribute _ :: AttributeName(_, name) :: AttributeNotEqual _ :: AttributeValue(_, value) :: CloseAttribute _ :: t ->
let selectedNodes = filterByAttr level acc name ((<>) value)
selectElements' FilterLevel.Root selectedNodes t
| OpenAttribute _ :: AttributeName(_, name) :: CloseAttribute _ :: t ->
let selectedNodes =
acc |> List.filter (attributes >> List.exists (HtmlAttribute.name >> (=) name))
selectElements' FilterLevel.Root selectedNodes t
| Checkbox _ :: t -> selectDescendantOfType "checkbox" t
| File _ :: t -> selectDescendantOfType "file" t
| Hidden _ :: t -> selectDescendantOfType "hidden" t
| Radio _ :: t -> selectDescendantOfType "radio" t
| Password _ :: t -> selectDescendantOfType "password" t
| Image _ :: t -> selectDescendantOfType "image" t
| Textbox _ :: t -> selectDescendantOfType "text" t
| Submit _ :: t -> selectDescendantOfType "submit" t
| Even _ :: t ->
let selectedNodes = selectEvenOdd true
selectElements' FilterLevel.Root selectedNodes t
| Odd _ :: t ->
let selectedNodes = selectEvenOdd false
selectElements' FilterLevel.Root selectedNodes t
| Button _ :: t ->
let selectedNodes =
filterByAttr level acc "type" ((=) "button")
|> Seq.append (acc |> Seq.collect (descendantsAndSelfNamed true [ "button" ]))
|> Seq.toList
selectElements' FilterLevel.Root selectedNodes t
| Checked _ :: t ->
let selectedNodes = attrExists level acc "checked"
selectElements' FilterLevel.Root selectedNodes t
| EmptyNode _ :: t ->
let selectedNodes =
acc
|> Seq.collect (
descendantsAndSelf true (fun _ -> true)
>> Seq.filter (fun d ->
String.IsNullOrWhiteSpace(d |> directInnerText)
&& (d |> descendants true (fun _ -> true)) |> Seq.isEmpty)
)
|> Seq.toList
selectElements' FilterLevel.Root selectedNodes t
| Selected _ :: t ->
let selectedNodes = attrExists level acc "selected"
selectElements' FilterLevel.Root selectedNodes t
| Disabled _ :: t ->
let selectedNodes = attrExists level acc "disabled"
selectElements' FilterLevel.Root selectedNodes t
| Enabled _ :: t ->
let selectedNodes =
acc
|> getTargets level
|> Seq.filter (attributes >> Seq.exists (HtmlAttribute.name >> (=) "disabled") >> not)
|> Seq.toList
selectElements' FilterLevel.Root selectedNodes t
| AllChildren _ :: t -> selectElements' FilterLevel.Descendants acc t
| DirectChildren _ :: t -> selectElements' FilterLevel.Children acc t
| [] -> acc
| tok -> failwithf "Invalid token: %A" tok
selectElements' FilterLevel.Descendants nodes tokens
let internal Select nodes selector =
let tokenizer = CssSelectorTokenizer()
match tokenizer.Tokenize selector with
| [] -> []
| tokens -> List.ofSeq nodes |> selectCssElements tokens
/// Gets descendants matched by Css selector
let cssSelect node selector = Select [ node ] selector
// --------------------------------------------------------------------------------------
[<Extension>]
/// Extension methods with operations on HTML nodes
type HtmlNodeExtensions =
/// Gets the given nodes name
[<Extension>]
static member Name(n: HtmlNode) = HtmlNode.name n
/// Gets all of the nodes immediately under this node
[<Extension>]
static member Elements(n: HtmlNode) = HtmlNode.elements n
/// <summary>
/// Gets all of the elements of the current node, which match the given set of names
/// </summary>
/// <param name="n">The given node</param>
/// <param name="names">The set of names by which to map the elements</param>
[<Extension>]
static member Elements(n: HtmlNode, names: seq<string>) = HtmlNode.elementsNamed names n
/// <summary>
/// Gets all of the elements of the current node, which match the given name
/// </summary>
/// <param name="n">The given node</param>
/// <param name="name">The name by which to map the elements</param>
[<Extension>]
static member Elements(n: HtmlNode, name: string) = HtmlNode.elementsNamed [ name ] n
/// <summary>
/// Gets all of the descendants of the current node that satisfy the predicate
/// </summary>
/// <param name="n">The given node</param>
/// <param name="predicate">The predicate for which descendants to return</param>
/// <param name="recurseOnMatch">If a match is found continues down the tree matching child elements</param>
[<Extension>]
static member Descendants(n: HtmlNode, predicate, recurseOnMatch) =
HtmlNode.descendants recurseOnMatch predicate n
/// <summary>
/// Gets all of the descendants of the current node that satisfy the predicate
/// The current node is also considered in the comparison
/// </summary>
/// <param name="n">The given node</param>
/// <param name="predicate">The predicate for which descendants to return</param>
/// <param name="recurseOnMatch">If a match is found continues down the tree matching child elements</param>
[<Extension>]
static member DescendantsAndSelf(n: HtmlNode, predicate, recurseOnMatch) =
HtmlNode.descendantsAndSelf recurseOnMatch predicate n
/// <summary>
/// Gets all of the descendants of the current node that satisfy the predicate
/// Recurses on match
/// </summary>
/// <param name="n">The given node</param>
/// <param name="predicate">The predicate for which descendants to return</param>
[<Extension>]
static member Descendants(n: HtmlNode, predicate) =
let recurseOnMatch = true
HtmlNode.descendants recurseOnMatch predicate n
/// <summary>
/// Gets all of the descendants of the current node that satisfy the predicate
/// The current node is also considered in the comparison
/// Recurses on match
/// </summary>
/// <param name="n">The given node</param>
/// <param name="predicate">The predicate for which descendants to return</param>
[<Extension>]
static member DescendantsAndSelf(n: HtmlNode, predicate) =
let recurseOnMatch = true
HtmlNode.descendantsAndSelf recurseOnMatch predicate n
/// Gets all of the descendants of the current node
/// Recurses on match
[<Extension>]
static member Descendants(n: HtmlNode) =
let recurseOnMatch = true
let predicate = fun _ -> true
HtmlNode.descendants recurseOnMatch predicate n
/// Gets all of the descendants of the current node
/// The current node is also considered in the comparison
/// Recurses on match
[<Extension>]
static member DescendantsAndSelf(n: HtmlNode) =
let recurseOnMatch = true
let predicate = fun _ -> true
HtmlNode.descendantsAndSelf recurseOnMatch predicate n
/// <summary>
/// Gets all of the descendants of the current node, which match the given set of names
/// </summary>
/// <param name="n">The given node</param>
/// <param name="names">The set of names by which to map the descendants</param>
/// <param name="recurseOnMatch">If a match is found continues down the tree matching child elements</param>
[<Extension>]
static member Descendants(n: HtmlNode, names: seq<string>, recurseOnMatch) =
HtmlNode.descendantsNamed recurseOnMatch names n
/// <summary>
/// Gets all of the descendants of the current node, which match the given set of names
/// The current node is also considered in the comparison
/// </summary>
/// <param name="n">The given node</param>
/// <param name="names">The set of names by which to map the descendants</param>
/// <param name="recurseOnMatch">If a match is found continues down the tree matching child elements</param>
[<Extension>]
static member DescendantsAndSelf(n: HtmlNode, names: seq<string>, recurseOnMatch) =
HtmlNode.descendantsAndSelfNamed recurseOnMatch names n
/// <summary>
/// Gets all of the descendants of the current node, which match the given set of names
/// Recurses on match
/// </summary>
/// <param name="n">The given node</param>
/// <param name="names">The set of names by which to map the descendants</param>
[<Extension>]
static member Descendants(n: HtmlNode, names: seq<string>) =
let recurseOnMatch = true
HtmlNode.descendantsNamed recurseOnMatch names n
/// <summary>
/// Gets all of the descendants of the current node, which match the given set of names
/// The current node is also considered in the comparison
/// Recurses on match
/// </summary>
/// <param name="n">The given node</param>
/// <param name="names">The set of names by which to map the descendants</param>
[<Extension>]
static member DescendantsAndSelf(n: HtmlNode, names: seq<string>) =
let recurseOnMatch = true
HtmlNode.descendantsAndSelfNamed recurseOnMatch names n
/// <summary>
/// Gets all of the descendants of the current node, which match the given name
/// </summary>
/// <param name="n">The given node</param>
/// <param name="name">The name by which to map the descendants</param>
/// <param name="recurseOnMatch">If a match is found continues down the tree matching child elements</param>
[<Extension>]
static member Descendants(n: HtmlNode, name: string, recurseOnMatch) =
HtmlNode.descendantsNamed recurseOnMatch [ name ] n
/// <summary>
/// Gets all of the descendants of the current node, which match the given name
/// The current node is also considered in the comparison
/// </summary>
/// <param name="n">The given node</param>
/// <param name="name">The name by which to map the descendants</param>
/// <param name="recurseOnMatch">If a match is found continues down the tree matching child elements</param>
[<Extension>]
static member DescendantsAndSelf(n: HtmlNode, name: string, recurseOnMatch) =
HtmlNode.descendantsAndSelfNamed recurseOnMatch [ name ] n
/// <summary>
/// Gets all of the descendants of the current node, which match the given name
/// Recurses on match
/// </summary>
/// <param name="n">The given node</param>
/// <param name="name">The name by which to map the descendants</param>
[<Extension>]
static member Descendants(n: HtmlNode, name: string) =
let recurseOnMatch = true
HtmlNode.descendantsNamed recurseOnMatch [ name ] n
/// <summary>
/// Gets all of the descendants of the current node, which match the given name
/// The current node is also considered in the comparison
/// Recurses on match
/// </summary>
/// <param name="n">The given node</param>
/// <param name="name">The name by which to map the descendants</param>
[<Extension>]
static member DescendantsAndSelf(n: HtmlNode, name: string) =
let recurseOnMatch = true
HtmlNode.descendantsAndSelfNamed recurseOnMatch [ name ] n
/// <summary>
/// Gets all of the descendants of the current node that satisfy the predicate
/// </summary>
/// <param name="n">The given node</param>
/// <param name="predicate">The predicate for which descendants to return</param>
/// <param name="recurseOnMatch">If a match is found continues down the tree matching child elements</param>
[<Extension>]
static member DescendantsWithPath(n: HtmlNode, predicate, recurseOnMatch) =
HtmlNode.descendantsWithPath recurseOnMatch predicate n
/// <summary>
/// Gets all of the descendants of the current node that satisfy the predicate
/// The current node is also considered in the comparison
/// </summary>
/// <param name="n">The given node</param>
/// <param name="predicate">The predicate for which descendants to return</param>
/// <param name="recurseOnMatch">If a match is found continues down the tree matching child elements</param>
[<Extension>]
static member DescendantsAndSelfWithPath(n: HtmlNode, predicate, recurseOnMatch) =
HtmlNode.descendantsAndSelfWithPath recurseOnMatch predicate n
/// <summary>
/// Gets all of the descendants of the current node that satisfy the predicate
/// Recurses on match
/// </summary>
/// <param name="n">The given node</param>
/// <param name="predicate">The predicate for which descendants to return</param>
[<Extension>]
static member DescendantsWithPath(n: HtmlNode, predicate) =
let recurseOnMatch = true
HtmlNode.descendantsWithPath recurseOnMatch predicate n
/// <summary>
/// Gets all of the descendants of the current node that satisfy the predicate
/// The current node is also considered in the comparison
/// Recurses on match
/// </summary>
/// <param name="n">The given node</param>
/// <param name="predicate">The predicate for which descendants to return</param>
[<Extension>]
static member DescendantsAndSelfWithPath(n: HtmlNode, predicate) =
let recurseOnMatch = true
HtmlNode.descendantsAndSelfWithPath recurseOnMatch predicate n
/// Gets all of the descendants of the current node
/// Recurses on match
[<Extension>]
static member DescendantsWithPath(n: HtmlNode) =
let recurseOnMatch = true
let predicate = fun _ -> true
HtmlNode.descendantsWithPath recurseOnMatch predicate n
/// Gets all of the descendants of the current node
/// The current node is also considered in the comparison
/// Recurses on match
[<Extension>]
static member DescendantsAndSelfWithPath(n: HtmlNode) =
let recurseOnMatch = true
let predicate = fun _ -> true
HtmlNode.descendantsAndSelfWithPath recurseOnMatch predicate n
/// <summary>
/// Gets all of the descendants of the current node, which match the given set of names
/// </summary>
/// <param name="n">The given node</param>
/// <param name="names">The set of names by which to map the descendants</param>
/// <param name="recurseOnMatch">If a match is found continues down the tree matching child elements</param>
[<Extension>]
static member DescendantsWithPath(n: HtmlNode, names: seq<string>, recurseOnMatch) =
HtmlNode.descendantsNamedWithPath recurseOnMatch names n
/// <summary>
/// Gets all of the descendants of the current node, which match the given set of names
/// The current node is also considered in the comparison
/// </summary>
/// <param name="n">The given node</param>
/// <param name="names">The set of names by which to map the descendants</param>
/// <param name="recurseOnMatch">If a match is found continues down the tree matching child elements</param>
[<Extension>]
static member DescendantsAndSelfWithPath(n: HtmlNode, names: seq<string>, recurseOnMatch) =
HtmlNode.descendantsAndSelfNamedWithPath recurseOnMatch names n
/// <summary>
/// Gets all of the descendants of the current node, which match the given set of names
/// Recurses on match
/// </summary>
/// <param name="n">The given node</param>
/// <param name="names">The set of names by which to map the descendants</param>
[<Extension>]
static member DescendantsWithPath(n: HtmlNode, names: seq<string>) =
let recurseOnMatch = true
HtmlNode.descendantsNamedWithPath recurseOnMatch names n
/// <summary>
/// Gets all of the descendants of the current node, which match the given set of names
/// The current node is also considered in the comparison
/// Recurses on match
/// </summary>
/// <param name="n">The given node</param>
/// <param name="names">The set of names by which to map the descendants</param>
[<Extension>]
static member DescendantsAndSelfWithPath(n: HtmlNode, names: seq<string>) =
let recurseOnMatch = true
HtmlNode.descendantsAndSelfNamedWithPath recurseOnMatch names n
/// <summary>
/// Gets all of the descendants of the current node, which match the given name
/// </summary>
/// <param name="n">The given node</param>
/// <param name="name">The name by which to map the descendants</param>
/// <param name="recurseOnMatch">If a match is found continues down the tree matching child elements</param>
[<Extension>]
static member DescendantsWithPath(n: HtmlNode, name: string, recurseOnMatch) =
HtmlNode.descendantsNamedWithPath recurseOnMatch [ name ] n
/// <summary>
/// Gets all of the descendants of the current node, which match the given name
/// The current node is also considered in the comparison
/// </summary>
/// <param name="n">The given node</param>
/// <param name="name">The name by which to map the descendants</param>
/// <param name="recurseOnMatch">If a match is found continues down the tree matching child elements</param>
[<Extension>]
static member DescendantsAndSelfWithPath(n: HtmlNode, name: string, recurseOnMatch) =
HtmlNode.descendantsAndSelfNamedWithPath recurseOnMatch [ name ] n
/// <summary>
/// Gets all of the descendants of the current node, which match the given name
/// Recurses on match
/// </summary>
/// <param name="n">The given node</param>
/// <param name="name">The names by which to map the descendants</param>
[<Extension>]
static member DescendantsWithPath(n: HtmlNode, name: string) =
let recurseOnMatch = true
HtmlNode.descendantsNamedWithPath recurseOnMatch [ name ] n
/// <summary>
/// Gets all of the descendants of the current node, which match the given name
/// The current node is also considered in the comparison
/// Recurses on match
/// </summary>
/// <param name="n">The given node</param>
/// <param name="name">The names by which to map the descendants</param>
[<Extension>]
static member DescendantsAndSelfWithPath(n: HtmlNode, name: string) =
let recurseOnMatch = true
HtmlNode.descendantsAndSelfNamedWithPath recurseOnMatch [ name ] n
/// Gets all of the attributes of this node
[<Extension>]
static member Attributes(n: HtmlNode) = HtmlNode.attributes n
/// <summary>
/// Tries to select an attribute with the given name from the current node.
/// </summary>
/// <param name="n">The given node</param>
/// <param name="name">The name of the attribute to select</param>
[<Extension>]
static member TryGetAttribute(n: HtmlNode, name: string) = HtmlNode.tryGetAttribute name n
/// <summary>
/// Returns the attribute with the given name. If the
/// attribute does not exist then this will throw an exception
/// </summary>
/// <param name="n">The given node</param>
/// <param name="name">The name of the attribute to select</param>
[<Extension>]
static member Attribute(n: HtmlNode, name) = HtmlNode.attribute name n
/// <summary>
/// Return the value of the named attribute, or an empty string if not found.
/// </summary>
/// <param name="n">The given node</param>
/// <param name="name">The name of the attribute to get the value from</param>
[<Extension>]
static member AttributeValue(n: HtmlNode, name) = HtmlNode.attributeValue name n
/// <summary>
/// Returns true if the current node has an attribute that
/// matches both the name and the value
/// </summary>
/// <param name="n">The given node</param>
/// <param name="name">The name of the attribute</param>
/// <param name="value">The value of the attribute</param>
[<Extension>]
static member HasAttribute(n: HtmlNode, name, value) = HtmlNode.hasAttribute name value n
/// Returns true if the current node has the specified name
[<Extension>]
static member HasName(n: HtmlNode, name) = HtmlNode.hasName name n
/// Returns true if the current node has the specified id
[<Extension>]
static member HasId(n: HtmlNode, id) = HtmlNode.hasId id n
/// Returns true if the current node has the specified class
[<Extension>]
static member HasClass(n: HtmlNode, cssClass) = HtmlNode.hasClass cssClass n
/// Returns the inner text of the current node
[<Extension>]
static member InnerText(n: HtmlNode) = HtmlNode.innerText n
/// Returns the direct inner text of the current node
[<Extension>]
static member DirectInnerText(n: HtmlNode) = HtmlNode.directInnerText n