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
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Code:
Sub FetchWebData()
    Dim doc, req
    Set req = CreateObject("MSXML2.XMLHTTP")
    Set doc = CreateObject("HTMLFile")
    req.Open "GET", "https://www.earningswhispers.com/stocks/" & [A2], False
    req.send
    doc.body.innerHTML = req.responseText
    [B2] = doc.getElementById("datebox").ChildNodes(2).innerHTML
    [C2] = doc.getElementById("earningstime").innerHTML
    doc.Close
End Sub
 
Last edited:
Upvote 0
Priviet Sektor.

Thats great.

In https://www.earningswhispers.com/stocks/nke, just to right above the earnings date there is a correct mark: "✔" which indicates that the earnings date is confirmed. If the earnings date was unconfirmed it would be a grey circle with white "-" in middle. (eg. https://www.earningswhispers.com/stocks/amzn)

Could I extract that into D2 by means of maybe 1 or 0; "confrmed" or "unconfirmed"; or maybe TRUE or FALSE?

I tried adding code: "[D2] = doc.getElementById("epsconfirmed").innerHTML" to your code however it didnt work.

Bolshoe spasibo

T

Code:
Sub FetchWebData()
    Dim doc, req
    Set req = CreateObject("MSXML2.XMLHTTP")
    Set doc = CreateObject("HTMLFile")
    req.Open "GET", "https://www.earningswhispers.com/stocks/" & [A2], False
    req.send
    doc.body.innerHTML = req.responseText
    [B2] = doc.getElementById("datebox").ChildNodes(2).innerHTML
    [C2] = doc.getElementById("earningstime").innerHTML
    doc.Close
End Sub
 
Last edited:
Upvote 0
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
Sektor's VBA code has worked perfectly for last 4 years until yesterday. I think the HTML code must have changed. I am not really a programmer and my efoorts over last few hours to find a workaround have come to nothing.

Can anyone help me to extract from page for example "www.earningswhispers.com/stocks/nke" the given date("Jun 17")?

Sektor's original code - 3rd line from end "[B2] = doc.getElementById("datebox").ChildNodes(2).innerHTML" no longer works.
The rest is fine

VBA Code:
Sub FetchWebData()
    Dim doc, req
    Set req = CreateObject("MSXML2.XMLHTTP")
    Set doc = CreateObject("HTMLFile")
    req.Open "GET", "https://www.earningswhispers.com/stocks/" & [A2], False
    req.send
    doc.body.innerHTML = req.responseText
    [B2] = doc.getElementById("datebox").ChildNodes(2).innerHTML
    [C2] = doc.getElementById("earningstime").innerHTML
    doc.Close
End Sub
 
Upvote 0
This code can't work anymore as the data does not exist in the request responseText as it is !​
So you must investigate with your webbrowser inspector tool which request headers are now necessary​
or just leave the request in favour to pilot the webpage under IE …​
 
Upvote 0
Try...

VBA Code:
    [B2] = doc.getElementById("datebox").Children(2).innerHTML

Hope this helps!
 
Upvote 0
Domenic, do you check the content of responseText ?​
 
Upvote 0
Thanks Domenic. That works great!
VBA Code:
VBA Code:
    [B2] = doc.getElementById("datebox").Children(2).innerHTML
 
Upvote 0

Forum statistics

Threads
1,215,375
Messages
6,124,576
Members
449,173
Latest member
Kon123

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