Depends on: MiniHtmlParser and WebViewExtras v1.42
Sub Process_Globals
Private xui As XUI
End Sub
Sub Globals
Private WebViewExtras1 As WebViewExtras
Private WebView1 As WebView
Private HtmlParser As MiniHtmlParser
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("Layout")
WebViewExtras1.addWebChromeClient(WebView1, "B4A")
WebViewExtras1.addJavascriptInterface(WebView1, "B4A")
WebView1.LoadUrl("https://earth.nullschool.net/#current/wind/surface/level/overlay=temp/orthographic=109.96,15.97,1792/loc=110.427,15.670")
HtmlParser.Initialize
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub WebView1_PageFinished (Url As String)
Dim Javascript As String = $"B4A.CallSub('Process_HTML', false, document.getElementById("spotlight-panel").outerHTML)"$
Sleep(1000)
WebViewExtras1.executeJavascript(WebView1, Javascript)
Wait For Process_HTML(Html As String)
Log(Html)
Dim root As HtmlNode = HtmlParser.Parse(Html)
HtmlParser.PrintNode(root)
Dim SpotlightB As HtmlNode = HtmlParser.FindNode(root, "div", HtmlParser.CreateHtmlAttribute("name", "spotlight-b"))
If SpotlightB.IsInitialized Then
HtmlParser.PrintNode(SpotlightB)
Dim divs As List = HtmlParser.FindDirectNodes(SpotlightB, "div", Null)
If divs.Size > 0 Then
Dim div As HtmlNode = divs.Get(0)
Dim attribute As HtmlAttribute = div.Attributes.Get(0)
Dim Temparature As String = attribute.Value
Log(Temparature)
End If
End If
End Sub
Should be quite simple to extract other information from the html.
<div id="spotlight-panel" class="panel card">
<div class="vert-unchanged row">
<div data-name="spotlight-coords">15.67° N, 110.43° E</div>
<span class="gap0p25"></span>
<button data-name="hide-spotlight" data-controls="spotlight-panel" aria-labelledby="hide-spotlight-tt" data-tooltip="hide-spotlight-tt" title="Close Spotlight">
<span>✕</span>
<span id="hide-spotlight-tt" role="tooltip">Close Spotlight</span>
</button>
<span class="gap-neg0p5"></span>
</div>
<div data-name="spotlight-a" class="vert-unchanged row">
<div aria-label="220° @ 17 km/h">220° @ 17</div>
<span class="gap0p25"></span>
<button aria-labelledby="spotlight-a-units-tt" data-tooltip="spotlight-a-units-tt" title="Change Units">
<span>km/h</span>
<span id="spotlight-a-units-tt" role="tooltip">Change Units</span>
</button>
</div>
<div data-name="spotlight-b" class="vert-unchanged row">
<div aria-label="30.3 °C">30.3</div>
<span class="gap0p25"></span>
<button aria-labelledby="spotlight-b-units-tt" data-tooltip="spotlight-b-units-tt" title="Change Units">
<span>°C</span>
<span id="spotlight-b-units-tt" role="tooltip">Change Units</span>
</button>
</div>
</div>