How to trigger a webpage datepicker when doing web scraping?

S_White

New Member
Joined
May 8, 2017
Messages
25
Hello,

I'm trying to scrape what is known as the ' Yield calculation price' of a listed fixed income instrument. In order to get the right series, I have to set both a from and to date. These can be set by submitting the values to datepickers on the site, but the table underneath with the mentioned price doesn't get updated before either a javascript is called or that the 'toDate' is recognized.

I don't have much experience with how to trigger a javascript and I haven't succeed with pasting the values either. Below, you can see my short code though I would perfer to extract these values by using a XmlHttp request through http://www.nasdaqomxnordic.com/webproxy/DataFeedProxy.aspx but that I cannot figure out either.

Anyone who can take me to the next level?

VBA Code:
Sub GetDAta()
Dim IEapp As InternetExplorer, UrlPath As String

UrlPath = "http://www.nasdaqomxnordic.com/bonds/denmark/microsite?Instrument=XCSE5UNIK_A_26"
Set IEapp = New InternetExplorer
With IEapp
    .Navigate UrlPath
    .Visible = True
    Do Until .readyState = READYSTATE_COMPLETE
        DoEvents
    Loop
    With .document
        .getElementById("fromDate").Value = "2019-01-01"
        With .getElementById("toDate")
            .Value = "2019-12-31"
            .Focus
            .Click
        End With
    End With
End With
End Sub

Thanks in advance.
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
If you just need a quick and dirty approach you could use SendKeys "{ENTER}" otherwise it looks like a real pain.

VBA Code:
Sub GetData()
    Dim IEapp As Object
    Dim UrlPath As String
      
    Set IEapp = CreateObject("internetexplorer.application")
    IEapp.Visible = True
    
    UrlPath = "http://www.nasdaqomxnordic.com/bonds/denmark/microsite?Instrument=XCSE5UNIK_A_26"
    
    IEapp.navigate (UrlPath)
        
    Do
        DoEvents
    Loop Until IEapp.readystate = 4
    
    If IsObject(IEapp.document.getElementById("fromDate")) Then
        IEapp.document.getElementById("fromDate").Value = "2019-12-31"
        IEapp.document.getElementById("toDate").Value = "2020-06-11"
        IEapp.document.getElementById("toDate").Focus
        SendKeys "{ENTER}"
        IEapp.document.getElementById("nordicSearchBox").Focus
    End If
        
End Sub
 
Upvote 0
well then... you owe me one mate! Use IEapp.document.parentWindow.execScript "dbMicrositeFunctions.getHistoryData()"

both sendkeys and running execScript below worked for me..

VBA Code:
Sub GetData()
    Dim IEapp As Object
    Dim UrlPath As String
      
    Set IEapp = CreateObject("internetexplorer.application")
    IEapp.Visible = True
    
    UrlPath = "http://www.nasdaqomxnordic.com/bonds/denmark/microsite?Instrument=XCSE5UNIK_A_26"
    
    IEapp.navigate (UrlPath)
        
    Do
        DoEvents
    Loop Until IEapp.readystate = 4
    
    If IsObject(IEapp.document.getElementById("fromDate")) Then
        IEapp.document.getElementById("fromDate").Value = "2019-12-31"
        IEapp.document.getElementById("toDate").Value = "2020-06-11"
        IEapp.document.parentWindow.execScript "dbMicrositeFunctions.getHistoryData()"
    End If
        
End Sub
 
Upvote 0
Solution
Spot on, @QuietRiot - that did the trick! Rest is just pure reading of rows and cells in the table. Actually, I was looking for a way to trigger the script, but I just couldn't figure out the one I should go for.

Thx - really appreciated - and enjoy the weekend :)
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,155
Members
453,021
Latest member
Justyna P

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