Hello
I try to get the text in a <a> tag on a webpage.
However, I get an error:
The tags look like this:
So I try to get "Home", "Commands" and "Image".
This is my code:
A minimum project is added to this post.
Thanks a lot.
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).
The tags look like this:
HTML:
<div class="breadcrumbs">
<a href="../../home.html">Home</a> > <a href="../../commands.html">Commands</a> > <a href="../Image.htm">Image</a> > CreateRenderImage
</div>
So I try to get "Home", "Commands" and "Image".
This is my code:
B4X:
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
A minimum project is added to this post.
Thanks a lot.