I was trying to get some data from a webpage by giving a keyword "AABDG27" and then click on search button and finally collecting the search results last item that is market data category= ESZ. It is an open website so below code can be tested. Below is my code.It gives error in the line Set mydata = IE.Document.getElements....
Sub keyword_search_result()
Dim i As Long
Dim IE As Object
Dim objElement As Object
Dim objCollection As Object
Dim mydata As Object
Dim myval As String
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = False
IE.Navigate "http://www.platts.com/symbol-page-directories/symbol-search"
Do
DoEvents
Loop Until IE.ReadyState = 3
Do
DoEvents
Loop Until IE.ReadyState = 4
IE.Document.getElementById("ctl00_ctl00_contentBody_contentMain_txtSearchSymbol").Value = "AABDG27"
IE.Document.getElementById("ctl00_ctl00_contentBody_contentMain_btnSearch").Click
Do
DoEvents
Loop Until IE.ReadyState = 4
Set mydata = IE.Document.getElementsByClassName("divCellBottomMiddle")(0).getElementsByTagName("br")
i = 0
For Each objCollection In mydata
myval = mydata(i).PreviousSibling.wholeText
'Debug.Print i&; " "; myval
i = i + 1
If i = 11 Then
'this is the case when myval string will come as "ESZ"
'but with lot of space
Sheets("Sheet1").Range("A1") = Trim(Right(myval, 10))
End If
Next objCollection
IE.Quit
Set IE = Nothing
End Sub
so what should be changed, is there any better way to do it utilizing winhttprequest/XMLHTTP or something like that ?