Dim st As String = $"
<div class="col-9 ml-auto text-right p-0">
<span id="allPopulation" class=" allPopulation number-lg">32.519</span>
</div>
"$
Dim parser As MiniHtmlParser
parser.Initialize
Dim root As HtmlNode = parser.Parse(st)
Dim listgroup As HtmlNode = parser.FindNode(root, "div", parser.CreateHtmlAttribute("class", "col-9 ml-auto text-right p-0"))
If listgroup.IsInitialized Then
Dim span1 As HtmlNode = parser.FindNode(listgroup, "span", Null)
Log(parser.GetAttributeValue(span1, "class", ""))
End If
Hello. How can I get this value? >>> 32.519
I get this in the code above. >>> allPopulation number-lg
Dim st As String = $"
<div class="col-9 ml-auto text-right p-0">
<span id="allPopulation" class=" allPopulation number-lg">32.519</span>
</div>
"$
Dim parser As MiniHtmlParser
parser.Initialize
Dim RootN As HtmlNode = parser.Parse(st)
Dim listgroup As HtmlNode = parser.FindNode(RootN, "div", parser.CreateHtmlAttribute("class", "col-9 ml-auto text-right p-0"))
If listgroup.IsInitialized Then
Dim span1 As HtmlNode = parser.FindNode(listgroup, "span", Null)
Log(parser.GetTextFromNode(span1, 0)) "<<<<< this is it
Log(parser.GetAttributeValue(span1, "class", ""))
End If
Dim text As String = $"
<div class="col-9 ml-auto text-right p-0">
<span id="allPopulation" class=" allPopulation number-lg">32.519</span>
</div>
"$
Log(ReadValueSpan(text))
B4X:
Public Sub ReadValueSpan(Html As String) As String
Dim Result As String, Pattern As String = $"<\s*span[^>]*>(.*?)<\s*\/\s*span>"$
Dim Matcher As Matcher = Regex.Matcher(Pattern, Html)
If Matcher.Find Then Result = Matcher.Group(1)
Return Result
End Sub
Online regex tester and debugger with real-time match highlighting, detailed explanations, substitutions, unit tests, benchmarking, and code generation. Supports PCRE2, JavaScript, Python, Go, Java, .NET, Rust, POSIX ERE, and POSIX BRE.
I have seen that you have asked these questions before and since I am currently making an app that uses Regex a lot, I leave you the solution to your questions.
hi.. How can I get the value of the "span" element. Two separate values are required. (dataid="101" and dataid="102") How can I get the values "615" and "715". thanks... Dim st As String = $" 2023...
www.b4x.com
B4X:
Dim text As String = $"
<div class="col-9 ml-auto text-right p-0">
<span id="allPopulation" class=" allPopulation number-lg">32.519</span>
</div>
"$
For Each v As Object In ReadValueSpan(text)
Log(v)
Next
Dim text As String = $"
<div class="list-group">
<input type="checkbox" dataid="101" />
<a href="techno1">2023</a>
<span> 615 <a href="techno"><i class="fa fa-chevron-circle-right"></i></a></span>
</div>
<div class="list-group">
<input type="checkbox" dataid="102" />
<a href="techno2">2023</a>
<span> 715 <a href="techno"><i class="fa fa-chevron-circle-right"></i></a></span>
</div>
"$
For Each v As Object In ReadValueSpan(text)
Log(v)
Next
B4X:
Public Sub ReadValueSpan(Html As String) As List
Dim Pattern As String = $"<\s*span[^>]*>(.*?)<.*?\/span>"$
Dim Matcher As Matcher = Regex.Matcher(Pattern, Html)
Dim Result As List : Result.Initialize
Do While Matcher.Find
Result.Add(Matcher.Group(1))
Loop
Return Result
End Sub
Online regex tester and debugger with real-time match highlighting, detailed explanations, substitutions, unit tests, benchmarking, and code generation. Supports PCRE2, JavaScript, Python, Go, Java, .NET, Rust, POSIX ERE, and POSIX BRE.
I just saw that it may be a more direct solution than MiniHtmlParser, which also uses regular expressions. and that this question had already been asked in another post.
To provide a solution to both posts, I wrote that routine, which can guide you in using regular expressions in other solutions along with MiniHtmlParser.