GET date from web page

sal21

Active Member
Joined
Apr 1, 2002
Messages
291

Attachments

  • Immagine.jpg
    Immagine.jpg
    76.6 KB · Views: 14
As you have been told many, many times before:

Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at:


There is no need to repeat the link(s) provided above but if you have posted the question at other places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem. If you keep failing to follow the rules, you will most likely be banned.
 
Upvote 0

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
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

1697371321891.png


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.

1697371883497.png


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?
 
Upvote 0
Hmm... it shouldn't have truncated the string at all. That's odd.

WEBSERVICE is a hacky little trick that may not be around forever, and definitely has its limitations - not least that its only available (for now) in Excel. It is, in actual fact, a worksheet function that I'm calling for VBA. I've not seen much about it generally (and certainly nothing about using it with VBA), but you'll mostly see it used in conjunction with the FILTERXML function.

As for the HTML document object, besides the official docs the only other thing I can think of is to trawl through VB6 code (it is the same language as VBA, after all). Was there anything in particular you were after? If so, may be worth starting a new thread.
 
Upvote 0

Forum statistics

Threads
1,215,831
Messages
6,127,140
Members
449,362
Latest member
Bracelane

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top