I need to grab some public data from a website, but the data in question is only accessible if the user clicks in an link that opens a new IE window with the desired data. Despite being newbie to Excel / VBA I managed to do a rudimentary code able to click on the link that opens the window with the desired data. Here is my code:
So far everything is working fine.
Now I need a code to select the new opened window and save the source code of it's webpage to a local *.txt file. I have tried some examples, including queries to the first page that shows the desired data too, but none worked. The only way I found to grab the data was saving the source code of the second web page to disk and parsing it.
Can someone help me?
Code:
Public Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As LongPtr)
Sub NavigateClick()
Dim Browser As Object
Dim URL As String
Dim nTabs As Integer
Set Browser = CreateObject("InternetExplorer.Application")
URL = "this *.asp webpage contains the link to be clicked"
Browser.Navigate (URL)
Browser.Visible = True
Do
Loop Until Browser.ReadyState = READYSTATE_COMPLETE 'Waits for the load of the web page containing the link to be clicked
Sleep 1000
For nTabs = 0 To 25 'For loop to select the link
SendKeys "{TAB}"
Sleep 50
Next nTabs
SendKeys "{ENTER}" 'click on the link
Do
Loop Until Browser.ReadyState = READYSTATE_COMPLETE
Application.Wait DateAdd("s", 2, Now) 'Wait for new IE window that contains the source code to be saved to local file
Browser.Quit 'Close the first IE window
Set Browser = Nothing 'Frees memory
End Sub
So far everything is working fine.
Now I need a code to select the new opened window and save the source code of it's webpage to a local *.txt file. I have tried some examples, including queries to the first page that shows the desired data too, but none worked. The only way I found to grab the data was saving the source code of the second web page to disk and parsing it.
Can someone help me?