VBA - Extract info from Webpage

tttommy2

Board Regular
Joined
Oct 1, 2012
Messages
55
Hi there

I have a spreadsheet with a stockticker in A2. Lets say for example "NKE" which is Nike's stock ticker.

I want some code which will go to the stockticker page on www.earningswhispers.com. So in my example this would be:

https://www.earningswhispers.com/stocks/nke

And then I would like to extract extract from this page the given date("Jun 29") to B2, and given time ("4:15 PM ET") to C2.

I have played about with Data Web Query, however I cant get anything to work.

Thanks

T
 
That's so weird as yesterday when I have checked out the responseText it was 'empty' and today it works !​
So my post #7 is wrong, sorry guys …​
 
Upvote 0

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
As no issue today :rolleyes: another way according to each element ID / Class​
(on VBE side the reference Microsoft HTML Object Library must be activated) :​
VBA Code:
Sub DemoReq1()
         [B2:D2].ClearContents
    With CreateObject("WinHttp.WinHttpRequest.5.1")
        .Open "GET", "https://www.earningswhispers.com/stocks/" & [A2].Text, False
        .setRequestHeader "DNT", "1"
         On Error Resume Next
        .send
         If .Status = 200 Then T$ = .responseText
    End With
         On Error GoTo 0
    If T = "" Then
        Beep
    Else
        With New HTMLDocument
            .body.innerHTML = T
             [B2:D2].Value2 = Array(.querySelector("#datebox>.mainitem").innerText, .all.earningstime.innerText, _
                                    -(InStr(.all.epsconfirmed.title, "not confirmed") = 0))
        End With
    End If
End Sub
 
Upvote 0
Solution
I just realise that also the code Domenic gave me back in June 18, 2017 also stop working the last few days.

Originally if the earnings date is confirmed with a correct mark: "✔" to right above the earnings date then "1" returned in D2 .
And if the earnings date is unconfirmed with grey circle with white "-" in middle to right above the earnings date then "0" returned in D2.

www.earningswhispers.com/stocks/nvda is confirmed with a ✔ so "1" returned in D2.
www.earningswhispers.com/stocks/nke is unconfirmed with grey circle with white "-" in middle so "0" returned in D2.

Any ideas on how to get Dominic's original code below working again?
Try...

Code:
    If InStr(1, doc.getElementById("epsconfirmed").getAttribute("classname"), "icon-checkmark", vbTextCompare) > 0 Then
        [D2] = 1
    Else
        [D2] = 0
    End If

Hope this helps!
 
Upvote 0
Sorry Marc L. You right. I'm very much a novice and I couldn't get your code to work yesterday. However today after some googling on your instruction to activate Microsoft HTML Object Library I got it to work perfectly.

Thank you for yor help and patience.
 
Upvote 0
As you could ask here ! Anyway, well done and thanks !​
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,732
Members
448,987
Latest member
marion_davis

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