2

i was wondering if you could tell me if there is a way to tell if there is Json that get from a site, i was working with the sydney KWS site and someone was able to tell me what their JSON page was, the page i am looking at is https://www.bne.com.au/passenger/flights/arrivals-departures any help would be great i need to get the flight information for departure from it,

I have taken a look at the backend and found that there is java been used to get the infoamtion, and found that there is a redirect when you first load the page but i could make head ot tails of that

Adam Wolarczuk
  • 105
  • 1
  • 8
  • Are you asking how to tell if there is a URL associated with a given website that would give a JSON response? Then the answer is Please consult the public API documentation provided by the site owner. – GSerg Nov 18 '19 at 11:25

1 Answers1

2

Open the webpage https://www.bne.com.au/passenger/flights/arrivals-departures in a browser (e. g. Chrome) and press F12 to open Developer tools. Go to Network tab, reload the page F5, enter json as filter string, then you can see the requests are logged:

requests

Inspect logged requests, the one having the largest size in that case contains the flights data. Open the request, here you can see URL on Headers tab (unix timestamp is sent as nocache parameter to disable caching):

json headers

There is response content on Preview and Response tabs:

json resp

Here is VBA example showing how that data could be retrieved. Import JSON.bas module into the VBA project for JSON processing.

Option Explicit

Sub test()

    Dim url As String
    Dim resp As String
    Dim data
    Dim state As String
    Dim body()
    Dim head()

    url = "https://www.bne.com.au/sites/default/files/00API-Today.json?nocache=" & CStr(epochTimeStamp(Now))
    ' Retrieve JSON content
    With CreateObject("MSXML2.XMLHTTP")
        .Open "GET", url, True
        .send
        Do Until .readyState = 4: DoEvents: Loop
        resp = .responseText
    End With
    ' Parse JSON sample
    JSON.Parse resp, data, state
    If state = "Error" Then MsgBox "Invalid JSON": End
    ' Convert JSON to 2D Array
    JSON.ToArray data, body, head
    ' Output to worksheet #1
    output head, body, ThisWorkbook.Sheets(1)
    MsgBox "Completed"

End Sub

Sub output(head, body, ws As Worksheet)

    With ws
        .Activate
        .Cells.Delete
        With .Cells(1, 1)
            .Resize(1, UBound(head) - LBound(head) + 1).Value = head
            .Offset(1, 0).Resize( _
                    UBound(body, 1) - LBound(body, 1) + 1, _
                    UBound(body, 2) - LBound(body, 2) + 1 _
                ).Value = body
        End With
        .Columns.AutoFit
    End With

End Sub

Function epochTimeStamp(dateTime)

    epochTimeStamp = (dateTime - 25569) * 86400

End Function

The output for me is as follows (fragment):

output

BTW, the similar approach applied in other answers.

omegastripes
  • 12,351
  • 4
  • 45
  • 96
  • mate this is so great two things if thats ok, i am working in python is there any way you can help me which the code for that, and also all i need is the departure info if trhere a way just osee that – Adam Wolarczuk Nov 18 '19 at 23:41
  • Please post another question tagged Python, and specify the URL from my answer. – omegastripes Nov 19 '19 at 04:15
  • hi mate see if you can hlp n this one https://stackoverflow.com/questions/58945659/there-are-two-sites-i-am-trying-to-find-if-they-have-api-json-back-ends – Adam Wolarczuk Nov 20 '19 at 05:08