Reputation: 1381
I would like to take information from those two pages that are similar:
http://www.quotenet.com/index/market-movers/S&P_500
http://www.quotenet.com/index/market-movers/CAC_40
I already have a code that works for one page (I want to get the first two movers in the table):
Dim ie As InternetExplorer, doc As HTMLDocument
Dim TopMoverTable As Object
Dim TopMoverTable2 As Object
Set ie = CreateObject("InternetExplorer.Application")
ie.navigate "http://www.quotenet.com/index/market-movers/S&P_500"
Do
DoEvents
Loop Until ie.readyState = READYSTATE_COMPLETE
Set doc = ie.document
Set TopMoverTable = doc.getElementsByTagName("TABLE")(2)
Cells(1, 2) = Split(TopMoverTable.getElementsByTagName("TD")(0).innerText, vbCrLf)(0)
Cells(1, 3) = Split(TopMoverTable.getElementsByTagName("TD")(4).innerText, vbCrLf)(1)
Cells(2, 2) = Split(TopMoverTable.getElementsByTagName("TD")(11).innerText, vbCrLf)(0)
Cells(2, 3) = Split(TopMoverTable.getElementsByTagName("TD")(15).innerText, vbCrLf)(1)
'ie.navigate "http://www.quotenet.com/index/market-movers/CAC_40"
' Do
' DoEvents
' Loop Until ie.readyState = READYSTATE_COMPLETE
'
' Set doc = ie.document
'
' Set TopMoverTable2 = doc.getElementsByTagName("TABLE")(2)
ie.Application.Quit
I commented the code that does not work.
How I can read those two pages?
Upvotes: 0
Views: 60
Reputation: 74
You were missing TopMoverTable2 in your code. Now, I have manipulated your code.
Try below code
Dim ie As InternetExplorer, doc As HTMLDocument
Dim TopMoverTable As Object
Dim TopMoverTable2 As Object
Set ie = CreateObject("InternetExplorer.Application")
ie.navigate "http://www.quotenet.com/index/market-movers/S&P_500"
Do
DoEvents
Loop Until ie.readyState = READYSTATE_COMPLETE
Set doc = ie.document
Set TopMoverTable = doc.getElementsByTagName("TABLE")(2)
Cells(1, 2) = Split(TopMoverTable.getElementsByTagName("TD") (0).innerText, vbCrLf)(0)
Cells(1, 3) = Split(TopMoverTable.getElementsByTagName("TD")(4).innerText, vbCrLf)(1)
Cells(2, 2) = Split(TopMoverTable.getElementsByTagName("TD")(11).innerText, vbCrLf)(0)
Cells(2, 3) = Split(TopMoverTable.getElementsByTagName("TD")(15).innerText, vbCrLf)(1)
ie.navigate "http://www.quotenet.com/index/market-movers/CAC_40"
Do
DoEvents
Loop Until ie.readyState = READYSTATE_COMPLETE
Set doc = ie.document
Set TopMoverTable2 = doc.getElementsByTagName("TABLE")(2)
Cells(5, 2) = Split(TopMoverTable2.getElementsByTagName("TD")(0).innerText, vbCrLf)(0)
Cells(5, 3) = Split(TopMoverTable2.getElementsByTagName("TD")(4).innerText, vbCrLf)(1)
Cells(6, 2) = Split(TopMoverTable2.getElementsByTagName("TD")(11).innerText, vbCrLf)(0)
Cells(6, 3) = Split(TopMoverTable2.getElementsByTagName("TD")(15).innerText, vbCrLf)(1)
ie.Application.Quit
Upvotes: 1