Android Question Could you please help me get some data from a web page

MicroDrie

Active Member
Licensed User
1623014784301.png

If you mean the data by the very brief description of a black box, I have to disappoint you. It is a pop-up menu with which you can influence the display. If you really want to download data to do something with it yourself, I have to disappoint you. As far as I can see, the website has not published an API for such an application.

Update: If you remain very vague about what exactly you want to achieve, it will be very difficult to help you. You can find more information about the underlying data of that website at https://www.weather.gov/documentation/services-web-api.
 
Last edited:
Upvote 0

NGUYEN TUAN ANH

Member
Licensed User
I want get only data in this black box
Screenshot_2021-06-07-08-06-30-91.jpg

[QUOTE = "MicroDrie, bài đăng: 827939, thành viên: 109738"]
[ATTACH = full] 114565 [/ ATTACH]
Nếu bạn muốn nói dữ liệu bằng cách mô tả rất ngắn gọn về hộp đen, thì tôi phải làm bạn thất vọng. Nó là một menu bật lên mà bạn có thể tác động đến màn hình. Nếu bạn thực sự muốn tải xuống dữ liệu để tự mình làm điều gì đó với nó, tôi phải làm bạn thất vọng. Theo như tôi thấy, trang web đã không xuất bản một API cho một ứng dụng như vậy.

Cập nhật: Nếu bạn vẫn còn mơ hồ về những gì chính xác mà bạn muốn đạt được, sẽ rất khó để giúp bạn. You can find more information about the base data of the page web that at https://www.weather.gov/documentation/services-web-api .
[/ TRÍCH DẪN]
 
Upvote 0

NGUYEN TUAN ANH

Member
Licensed User
[QUOTE = "Sandman, bài đăng: 827903, thành viên: 104625"]
Bạn muốn lấy dữ liệu nào?
[/TRÍCH DẪN]
Tôi want get data in this black box
 

Attachments

  • Screenshot_2021-06-07-08-06-30-91.jpg
    Screenshot_2021-06-07-08-06-30-91.jpg
    118.9 KB · Views: 29
Upvote 0

Erel

Administrator
Staff member
Licensed User
Depends on: MiniHtmlParser and WebViewExtras v1.42
B4X:
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>
 
Upvote 0

mc73

Well-Known Member
Licensed User
Depends on: MiniHtmlParser and WebViewExtras v1.42
B4X:
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>

Erel, could you please explain the necessity of sleep(1000) right before the javascript? is it, for example, to make sure that our URL is actually finished loading?
 
Upvote 0

Erel

Administrator
Staff member
Licensed User
Load the site in your browser: https://earth.nullschool.net/#curre...ographic=109.96,15.97,1792/loc=110.427,15.670
You will see that the information balloon is not immediately available.

A better solution is to actually do something like:
B4X:
For i = 1 to 10
  WebViewExtras1.executeJavascript(WebView1, Javascript)
    Wait For Process_HTML(Html As String)
   'try to parse
   'if successful - exit loop or return from sub
    'otherwise sleep and continue
    Sleep(1000)
Next
 
Upvote 0
Top