有没有办法告诉网站上是否存在json

我想知道您是否可以告诉我是否有一种方法可以确定是否有来自站点的Json,我正在悉尼KWS网站工作,有人可以告诉我他们的JSON页面是什么,我正在查看的页面是https://www.bne.com.au/passenger/flights/arrivals-departures,任何帮助都将非常有用,我需要从该页面获取出发的航班信息,

我看了看后端,发现有Java用于获取信息,并发现在首次加载页面时存在重定向,但是我可以为此做些事情

q5070212 回答:有没有办法告诉网站上是否存在json

在浏览器(例如Chrome)中打开网页https://www.bne.com.au/passenger/flights/arrivals-departures,然后按 F12 打开开发人员工具。转到网络选项卡,重新加载页面 F5 ,输入json作为过滤字符串,然后您可以看到记录了请求:

requests

检查记录的请求,在这种情况下,最大的请求包含排期数据。打开请求,您可以在“标题”选项卡上看到URL(unix时间戳作为nocache参数发送以禁用缓存):

json headers

“预览”和“响应”选项卡上有响应内容:

json resp

这是VBA示例,显示了如何检索该数据。 JSON.bas模块导入VBA项目中以进行JSON处理。

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,ThisWorkbook.Sheets(1)
    MsgBox "Completed"

End Sub

Sub output(head,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

对我来说,输出如下(片段):

output

顺便说一句,类似的方法适用于in other answers

本文链接:https://www.f2er.com/3081569.html

大家都在问