0

我正在尝试使用网站https://www.trainline.fr/search获取火车信息(日期、时间和价格)

我想使用 Excel VBA(我正在尝试通过 MSXML2.XMLHTT 的 POST 请求方法)发送 JSon 请求并在表格中解析答案。

我不知道右侧面板的哪个部分

IE - 开发工具截图在我的代码中使用

发送的请求如下所示:

{"search":{"departure_date":"2018-04-01T10:00:00UTC","return_date":null,"cuis":{},"systems":["sncf","db","idtgv","ouigo","trenitalia","ntv","hkx","renfe","benerail","ocebo","westbahn","leoexpress","locomore","busbud","flixbus","distribusion","city_airport_train","obb","timetable"],"exchangeable_part":null,"source":null,"is_previous_available":false,"is_next_available":false,"departure_station_id":"4916","via_station_id":null,"arrival_station_id":"233","exchangeable_pnr_id":null,"passenger_ids":["173716784"],"card_ids":["7118357"]}}

我实际上正在使用更简单的导航方法,但我想以更有效和更有趣的方法取得进展。

我的实际代码:

Dim objHTTP As Object
Dim Json As String 
Dim result As String

'here I am pulling in the request {"search":{"departure_date":"2018...
Json = Worksheets("Test").Range("A1")

Set objHTTP = CreateObject("MSXML2.XMLHTTP.6.0")
URL = "https://www.trainline.fr/api/v5_1/search"

objHTTP.Open "POST", URL, False
objHTTP.setRequestHeader "Content-type", "application/json"
objHTTP.send (Json)

result = objHTTP.responseText

感谢您分享你的知识

4

0 回答 0