Sigh.. curiosity got the better of me. Here you go:
VBA Code:
Public Sub GetGithubUpdate()
Dim URL As String
URL = "https://api.github.com/repos/gnekt/geolocalizzazione-comuni-italiani"
MsgBox GetDetails(URL, "updated_at")
End Sub
Public Function GetDetails(ByVal URL As String, Optional ByVal JSONField As String = "updated_at") As Date
Dim JSON As String, UpdatedAt As Variant, UpdatedDate As Date
JSON = Application.WebService(URL)
UpdatedAt = Split(Split(JSON, JSONField & Chr(34) & ":" & Chr(34))(1), Chr(34))(0)
UpdatedDate = CDate(Split(UpdatedAt, "T")(0))
GetDetails = UpdatedDate
End Function
View attachment 100352
Now you got my attention.
I have tried a different approach, but your code seems to be lighter, faster and more accurate
Nevertheless, here is my code:
VBA Code:
Public Sub GetDataFromWebPage()
Dim request As Object
Dim response As String
Dim html As New HTMLDocument
Dim URL As String
Dim webdata As Variant
URL = "https://github.com/gnekt/geolocalizzazione-comuni-italiani"
Set request = CreateObject("MSXML2.XMLHTTP")
request.Open "GET", URL, False
request.setRequestHeader "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT"
request.send
response = StrConv(request.responseBody, vbUnicode)
html.body.innerHTML = response
webdata = html.getElementsByTagName("relative-time").Item(1).innerText
Debug.Print webdata
End Sub
As you can see I use a HTML Document to scrape the data.
Many developers switched from using the
id attribute to
class attribute which makes addressing the right element more difficult.
I tried using
getElementsByClassName with the class
Link--secondary ml-2 but did not get the desired result.
I already know HTML/JS/CSS and the syntax seems to be the same, but not all Methods and Properties are supported by the VBA HTML Document Object.
Does anybody know where I can find a Reference of the Object Properties and Methods of the HTML Document Object, because even after hours spent searching I couldn't find anything.
It would be great having something like
W3Schools for VBA.
That'll be enough said about my approach, now let's talk about the
WebService Object.
Could you tell me something about it
?
I have set a breakpoint and this is what I got:
JSON = {"login":"gnekt","id":39567665,"node_id":"MDQ6VXNlcjM5NTY3NjY1","avatar_url":"https://avata"
But where is the rest of the String?