I try to get the text in a <a> tag on a webpage.
However, I get an error:
Waiting for debugger to connect...
Program started.
Error occurred on line: 276 (MiniHtmlParser)
java.lang.IndexOutOfBoundsException: Index 0 out of bounds for length 0
at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64)
...
Program terminated (StartMessageLoop was not called).
Private HtmlParser As MiniHtmlParser
HtmlParser.Initialize
Dim root As HtmlNode = HtmlParser.Parse(File.ReadString(File.DirAssets, "TestHTML.txt"))
Dim breadcrumbs As HtmlNode = HtmlParser.FindNode(root, "div", HtmlParser.CreateHtmlAttribute("class", "breadcrumbs"))
For Each n As HtmlNode In breadcrumbs.Children
Log(HtmlParser.GetTextFromNode(n, 0))
Next
In this code, I see the structure as this:
The <div> breadcrumbs has 3 childeren, the 3 <a> tags, they all have a Text value, why is it needed to check if the <a> has children to get their text value?
And if the text value is seen as a child, why would there be an out of bound exception, as they all have a text value?
I seem to miss something fundamental about these HTML tags.
But that is not what this library sees. Log the size and the n's (use one of the HtmlParser methods to see the content of the n's) to see what it sees.
Note: log the size of breadcrumbs children list